コード例 #1
0
        public static void GenerateReport(TestRun run, string outputFile, string screenshotLocation)
        {
            Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory);
            string template = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ReportGenerator/trx_report_template.html"));

            string result = Engine.Razor.RunCompile(
                template,
                "rawTemplate",
                null,
                new TestRunReport(run));

            //TODO: Implement screenshot logic here!

            if (File.Exists(outputFile))
            {
                Console.WriteLine("Deleting: " + outputFile);
                File.Delete(outputFile);
            }

            File.WriteAllText(outputFile, result);
        }
コード例 #2
0
        internal static TestRun DeserializeTRX(string trxPath)
        {
            TestRun testRun = new TestRun();

            using (Stream trxStream = new FileStream(trxPath, FileMode.Open, FileAccess.Read))
            {
                XDocument doc = XDocument.Load(trxStream);
                var run = doc.Root;

                testRun.Id = run.Attribute("id").Value;
                testRun.Name = run.Attribute("name").Value;
                testRun.RunUser = run.Attribute("runUser").Value;

                testRun.Times = DeserializeTimes(doc.Descendants(ns + "Times").FirstOrDefault());
                testRun.Results = DeserializeResults(doc.Descendants(ns + "UnitTestResult"));
                testRun.TestDefinitions = DeserializeTestDefinitions(doc.Descendants(ns + "UnitTest"));
                testRun.TestEntries = DeserializeTestEntries(doc.Descendants(ns + "TestEntry"));
                testRun.TestLists = DeserializeTestLists(doc.Descendants(ns + "TestList"));
                testRun.ResultSummary = DeserializeResultSummary(doc.Descendants(ns + "ResultSummary").FirstOrDefault());
            }
            return testRun;
        }
コード例 #3
0
        internal static string SerializeAndSaveTestRun(TestRun testRun, string targetPath)
        {
            XNamespace xmlns = "http://microsoft.com/schemas/VisualStudio/TeamTest/2010";
            XDocument doc =
                new XDocument(
                  new XElement("TestRun",
                        new XAttribute("id", testRun.Id),
                        new XAttribute("name", testRun.Name),
                        new XAttribute("runUser", testRun.RunUser),
                        new XElement("Times",
                            new XAttribute("creation", testRun.Times.Creation),
                            new XAttribute("queuing", testRun.Times.Queuing),
                            new XAttribute("start", testRun.Times.Start),
                            new XAttribute("finish", testRun.Times.Finish)),
                        new XElement("Results",
                            testRun.Results.Select(
                                utr =>
                                    new XElement("UnitTestResult",
                                        new XAttribute("computerName", utr.ComputerName),
                                        utr.Duration == null ? null : new XAttribute("duration", utr.Duration),
                                        utr.EndTime == null ? null : new XAttribute("endTime", utr.EndTime),
                                        utr.ExecutionId == null ? null : new XAttribute("executionId", utr.ExecutionId),
                                        utr.Outcome == null ? null : new XAttribute("outcome", utr.Outcome),
                                        utr.StartTime == null ? null : new XAttribute("startTime", utr.StartTime),
                                        new XAttribute("testId", utr.TestId),
                                        new XAttribute("testListId", utr.TestListId),
                                        new XAttribute("testName", utr.TestName),
                                        new XAttribute("testType", utr.TestType),
                                        new XElement("Output",
                                             utr.Output.StdOut == null ? null : new XElement("StdOut", utr.Output.StdOut),
                                             utr.Output.StdErr == null ? null : new XElement("StdErr", utr.Output.StdErr),
                                             utr.Output.ErrorInfo == null ? null :
                                             new XElement("ErrorInfo",
                                                  utr.Output.ErrorInfo.Message == null ? null : new XElement("Message", utr.Output.ErrorInfo.Message),
                                                  utr.Output.ErrorInfo.StackTrace == null ? null : new XElement("StackTrace", utr.Output.ErrorInfo.StackTrace)
                                                  ))))),
                      new XElement("TestDefinitions",
                           testRun.TestDefinitions.Select(
                                td => new XElement("UnitTest",
                                         new XAttribute("id", td.Id),
                                         new XAttribute("name", td.Name),
                                         new XAttribute("storage", td.Storage),
                                         new XElement("Execution",
                                            new XAttribute("id", td.Execution.Id)),
                                         new XElement("TestMethod",
                                            new XAttribute("codeBase", td.TestMethod.CodeBase),
                                            new XAttribute("className", td.TestMethod.ClassName),
                                            new XAttribute("name", td.TestMethod.Name),
                                            td.TestMethod.AdapterTypeName == null ? null : new XAttribute("adapterTypeName", td.TestMethod.AdapterTypeName))))),
                        new XElement("TestEntries",
                             testRun.TestEntries.Select(
                                te => new XElement("TestEntry",
                                          new XAttribute("testId", te.TestId),
                                          new XAttribute("executionId", te.ExecutionId),
                                          new XAttribute("testListId", te.TestListId)))),
                        new XElement("TestLists",
                            testRun.TestLists.Distinct().Select(
                                 tl => new XElement("TestList",
                                     new XAttribute("name", tl.Name),
                                     new XAttribute("id", tl.Id)))),
                        new XElement("ResultSummary",
                            new XAttribute("outcome", testRun.ResultSummary.Outcome),
                            new XElement("Counters",
                                new XAttribute("aborted", testRun.ResultSummary.Counters.Aborted),
                                new XAttribute("completed", testRun.ResultSummary.Counters.Completed),
                                new XAttribute("disconnected", testRun.ResultSummary.Counters.Disconnected),
                                new XAttribute("executed", testRun.ResultSummary.Counters.Еxecuted),
                                new XAttribute("failed", testRun.ResultSummary.Counters.Failed),
                                new XAttribute("inconclusive", testRun.ResultSummary.Counters.Inconclusive),
                                new XAttribute("inProgress", testRun.ResultSummary.Counters.InProgress),
                                new XAttribute("notExecuted", testRun.ResultSummary.Counters.NotExecuted),
                                new XAttribute("notRunnable", testRun.ResultSummary.Counters.NotRunnable),
                                new XAttribute("passed", testRun.ResultSummary.Counters.Passed),
                                new XAttribute("passedButRunAborted", testRun.ResultSummary.Counters.PassedButRunAborted),
                                new XAttribute("pending", testRun.ResultSummary.Counters.Pending),
                                new XAttribute("timeout", testRun.ResultSummary.Counters.Timeout),
                                new XAttribute("total", testRun.ResultSummary.Counters.Total),
                                new XAttribute("warning", testRun.ResultSummary.Counters.Warning)),
                            new XElement("RunInfos",
                                testRun.ResultSummary.RunInfos.Select(
                                    ri => new XElement("RunInfo",
                                        new XAttribute("computerName", ri.ComputerName),
                                        new XAttribute("outcome", ri.Outcome),
                                        new XAttribute("timestamp", ri.Timestamp),
                                        new XElement("Text", ri.Text)))))
                             )
                );

            doc.Root.SetDefaultXmlNamespace("http://microsoft.com/schemas/VisualStudio/TeamTest/2010");

            if (File.Exists(targetPath))
                File.Delete(targetPath);

            doc.Save(targetPath);

            var savedFileInfo = new FileInfo(targetPath);

            return savedFileInfo.FullName;
        }
コード例 #4
0
 public TestRunReport(TestRun run)
 {
     Run = run;
 }