/// <summary> /// Write out the result of exploring the tests /// </summary> /// <param name="test">The top-level test</param> /// <param name="spec">An OutputSpecification</param> public void WriteTestFile(ITest test, OutputSpecification spec) { string outputPath = Path.Combine(_workDirectory, spec.OutputPath); OutputWriter outputWriter = null; switch (spec.Format) { case "nunit3": outputWriter = new NUnit3XmlOutputWriter(); break; case "cases": outputWriter = new TestCaseOutputWriter(); break; //case "user": // Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase); // string dir = Path.GetDirectoryName(uri.LocalPath); // outputWriter = new XmlTransformOutputWriter(Path.Combine(dir, spec.Transform)); // break; default: throw new ArgumentException( string.Format("Invalid XML output format '{0}'", spec.Format), "spec"); } outputWriter.WriteTestFile(test, outputPath); Console.WriteLine("Tests ({0}) saved as {1}", spec.Format, outputPath); }
public override string WriteResultsToFile(Jargon jargon) { if (results == null) { return(string.Empty); } string ret = GetResultsFilePath(); if (string.IsNullOrEmpty(ret)) { return(string.Empty); } OutputWriter formatter; switch (jargon) { case Jargon.NUnitV2: formatter = new NUnit2XmlOutputWriter(DateTime.UtcNow); break; case Jargon.NUnitV3: formatter = new NUnit3XmlOutputWriter(DateTime.UtcNow); break; default: throw new InvalidOperationException($"Jargon {jargon} is not supported by this runner."); } formatter.WriteResultFile(results, ret); return(ret); }
public void SeveralTetRunTest() { // same logic as with the other tests, but with more than one test run var firstTestRun = new Mock <ITestRun>(); firstTestRun.Setup(t => t.Result).Returns(GetTestRunSample()); var secondTestRun = new Mock <ITestRun>(); secondTestRun.Setup(t => t.Result).Returns(GetTestRunSample()); _resultSummary.Setup(rs => rs.GetEnumerator()) .Returns(new List <ITestRun> { firstTestRun.Object, secondTestRun.Object }.GetEnumerator()); using (var writer = new StreamWriter(_tempPath)) { var nunit3Writer = new NUnit3XmlOutputWriter(DateTime.Now); nunit3Writer.WriteResultFile(_resultSummary.Object, writer); } // read the file and make sure that is correct var doc = new XmlDocument(); doc.Load(_tempPath); var runs = doc.SelectNodes(".//test-run"); Assert.Equal(1, runs.Count); var enviroment = doc.SelectNodes(".//environment"); Assert.Equal(1, enviroment.Count); }
public void SingleTestRunTest() { var testRun = new Mock <ITestRun>(); testRun.Setup(t => t.Result).Returns(GetTestRunSample()); // set the expectations of the mock, the important thing, we want to return a single test-run node _resultSummary.Setup(rs => rs.GetEnumerator()) .Returns(new List <ITestRun> { testRun.Object }.GetEnumerator()); using (var writer = new StreamWriter(_tempPath)) { var nunit3Writer = new NUnit3XmlOutputWriter(DateTime.Now); nunit3Writer.WriteResultFile(_resultSummary.Object, writer); } // read the file and make sure that is correct var doc = new XmlDocument(); doc.Load(_tempPath); // we just need to make sure we have a single test-run node and a single env node, the rest // was generated by nunit var runs = doc.SelectNodes(".//test-run"); Assert.Equal(1, runs.Count); var enviroment = doc.SelectNodes(".//environment"); Assert.Equal(1, enviroment.Count); }
protected virtual void PublishResults(TestResult testResults) { TestResultsConfig.PrintConfig(); Log.Info(this.tag, "Publishing results : " + DateTime.Now + "\nTotal count : {0}, Failed : {1}", testResults.AssertCount, testResults.FailCount); if (TestResultsConfig.IsRemote) { switch (TestResultsConfig.TestsResultsFormat) { case "plain_text": // We already published test results because in this case we publish each test results separately. See SetTextWriterForAndroidTestRunner() method. return; case "nunit2": var nunit2Writer = new NUnit2XmlOutputWriter(this.testsStartTime); var tcpwriter = this.NetworkWriter; nunit2Writer.WriteResultFile(testResults, tcpwriter); tcpwriter.Close(); Log.Info(this.tag, "Published tests results in nunit2 format"); return; case "nunit3": var nunit3Writer = new NUnit3XmlOutputWriter(this.testsStartTime); var newtworkWriter = this.NetworkWriter; nunit3Writer.WriteResultFile(testResults, newtworkWriter); newtworkWriter.Close(); Log.Info(this.tag, "Published tests results in nunit3 format"); return; } } else { // If we don't need to send test results to remote server, just return. return; } }
public override void WriteResultsToFile(TextWriter writer, Jargon jargon) { if (results == null) { return; } OutputWriter formatter; switch (jargon) { case Jargon.NUnitV2: formatter = new NUnit2XmlOutputWriter(DateTime.UtcNow); break; case Jargon.NUnitV3: formatter = new NUnit3XmlOutputWriter(DateTime.UtcNow); break; default: throw new InvalidOperationException($"Jargon {jargon} is not supported by this runner."); } formatter.WriteResultFile(results, writer); }
/// <summary> /// Write the result of a test run according to a spec. /// </summary> /// <param name="result">The test result</param> /// <param name="spec">An output specification</param> /// <param name="runSettings">Settings</param> /// <param name="filter">Filter</param> public void WriteResultFile(ITestResult result, OutputSpecification spec, IDictionary <string, object> runSettings, TestFilter filter) { //string outputPath = Path.Combine(_workDirectory, spec.OutputPath); // [DuongNT][BEGIN]: Get configured file path output // Write results log ResultSummary summary = new ResultSummary(result); int totalTCT = summary.TestCount; int passedTCT = summary.PassCount; int failedTCT = summary.FailedCount; int blockTCT = totalTCT - passedTCT - failedTCT; TLogger.Write(""); TLogger.Write("#####Summary#####"); TLogger.Write("##### Total #####"); TLogger.Write("##### " + totalTCT + " #####"); TLogger.Write("##### PASS #####"); TLogger.Write("##### " + passedTCT + " #####"); TLogger.Write("##### FAIL #####"); TLogger.Write("##### " + failedTCT + " #####"); TLogger.Write("##### BLOCK #####"); TLogger.Write("##### " + blockTCT + " #####"); TLogger.Write("##### Details #####"); TLogger.Write(""); string outputPath = TSettings.GetInstance().GetOutputFilePathName(); if (outputPath == "") { outputPath = Path.Combine(_workDirectory, spec.OutputPath); } TLogger.Write("Completed test-suite's execution!"); TLogger.Write("Writing results to: " + outputPath + "..."); // [DuongNT][END]: Get configured file path output OutputWriter outputWriter = null; switch (spec.Format) { case "nunit3": outputWriter = new NUnit3XmlOutputWriter(); break; case "nunit2": outputWriter = new NUnit2XmlOutputWriter(); break; //case "user": // Uri uri = new Uri(Assembly.GetExecutingAssembly().CodeBase); // string dir = Path.GetDirectoryName(uri.LocalPath); // outputWriter = new XmlTransformOutputWriter(Path.Combine(dir, spec.Transform)); // break; default: throw new ArgumentException( string.Format("Invalid XML output format '{0}'", spec.Format), "spec"); } outputWriter.WriteResultFile(result, outputPath, runSettings, filter); TLogger.Write("Results saved to: " + outputPath); }