예제 #1
0
        /// <summary>
        /// This should be called in TestCleanup when the test fails to save the execution
        /// artifacts for investigation.
        /// </summary>
        /// <remarks>Attachment on Linux machine will fail until this issue is resolved:
        /// https://github.com/microsoft/testfx/issues/619 </remarks>
        private void SaveArtifacts()
        {
            var artifactTestCaseFolder = Path.Combine(Directory.GetCurrentDirectory(),
                                                      "artifacts",
                                                      TestName,
                                                      TestCaseCount.ToString());

            if (!Directory.Exists(artifactTestCaseFolder))
            {
                Directory.CreateDirectory(artifactTestCaseFolder);
            }

            if (File.Exists(CfgJsonPath))
            {
                File.Copy(CfgJsonPath,
                          Path.Combine(artifactTestCaseFolder, "cfg.json"),
                          overwrite: true);
            }
            if (File.Exists(TenvJsonPath))
            {
                File.Copy(TenvJsonPath,
                          Path.Combine(artifactTestCaseFolder, "tenv.json"),
                          overwrite: true);
            }
            if (File.Exists(TestCodeFilePath))
            {
                File.Copy(TestCodeFilePath,
                          Path.Combine(artifactTestCaseFolder, TestCodeFileName),
                          overwrite: true);
            }

            var artifactInferOutFolder = Path.Combine(artifactTestCaseFolder, "infer-out");

            if (Directory.Exists(artifactInferOutFolder))
            {
                Directory.Delete(artifactInferOutFolder, true);
            }
            if (Directory.Exists(InferOutFolder))
            {
                Directory.Move(InferOutFolder, artifactInferOutFolder);
            }

            if (Cfg != null)
            {
                Cfg.GenerateDotFile(Path.Combine(artifactTestCaseFolder, "cfg.dot"));
                File.WriteAllText(Path.Combine(artifactTestCaseFolder, "cfg.txt"), Cfg.ToString());
            }
        }