static IEnumerable <TestReportBase> ReadInput(CommandArguments args) { if (string.IsNullOrWhiteSpace(args.InputPath)) { ProgramExit.Exit(ExitCode.InvalidInput, true); yield break; } ExitCode.ExitCodeData errorCode = ExitCode.Success; bool anyFailures = false; foreach (string path in args.AllPositionalArgs) { TestReportBase testReport = ReadInputInternal(path, ref errorCode); if (testReport != null) { yield return(testReport); } else { anyFailures = true; } } if (anyFailures && args.AllPositionalArgs.Count == 1) { // only one test report and it failed to read, exit ProgramExit.Exit(errorCode); yield break; } }
private testsuitesTestsuite ConvertTestsuite(TestReportBase testReport, int index) { // GUI test? testsuitesTestsuite ts = TryConvertTestsuite(testReport as XmlReport.GUITest.TestReport, index); if (ts != null) { return(ts); } // API test? ts = TryConvertTestsuite(testReport as XmlReport.APITest.TestReport, index); if (ts != null) { return(ts); } // BPT test? ts = TryConvertTestsuite(testReport as XmlReport.BPT.TestReport, index); if (ts != null) { return(ts); } // none of above, return the default testsuite with only common data, that is, no testcases ts = new testsuitesTestsuite(); FillTestsuiteCommonData(ts, testReport, index); return(ts); }
// For GUI / API / BPT tests private static void FillTestsuiteCommonData(testsuitesTestsuite ts, TestReportBase testReport, int index) { ts.id = index; // Starts at '0' for the first testsuite and is incremented by 1 for each following testsuite ts.package = testReport.TestAndReportName; ts.name = string.Format("TEST-{0,3:000}: {1}", index + 1, testReport.TestAndReportName); // other JUnit required fields ts.timestamp = testReport.TestRunStartTime; ts.hostname = testReport.HostName; if (string.IsNullOrWhiteSpace(ts.hostname)) { ts.hostname = "localhost"; } ts.time = testReport.TestDurationSeconds; // properties List <testsuiteProperty> properties = new List <testsuiteProperty>(ConvertTestsuiteCommonProperties(testReport)); ts.properties = properties.ToArray(); }
public static bool ConvertAndSave(CommandArguments args, TestReportBase input) { ConverterBase conv = null; // try to test if the input report is a GUI/API/BPT test report GUITestReport guiReport = input as GUITestReport; APITestReport apiReport = input as APITestReport; BPTReport bptReport = input as BPTReport; if (guiReport != null) { conv = new GUITestReportConverter(args, guiReport); } else if (apiReport != null) { conv = new APITestReportConverter(args, apiReport); } else if (bptReport != null) { conv = new BPTReportConverter(args, bptReport); } else { return(false); } if (!conv.Convert()) { return(false); } if (!conv.SaveFile()) { return(false); } return(true); }
static void Convert(CommandArguments args) { // input IEnumerable <TestReportBase> testReports = ReadInput(args); // output - none if (args.OutputFormats == OutputFormats.None) { ProgramExit.Exit(ExitCode.UnknownOutputFormat, true); return; } // output - junit if ((args.OutputFormats & OutputFormats.JUnit) == OutputFormats.JUnit) { // the output JUnit path must be NOT an exist directory if (Directory.Exists(args.JUnitXmlFile)) { OutputWriter.WriteLine(Properties.Resources.ErrMsg_JUnit_OutputCannotDir); ProgramExit.Exit(ExitCode.InvalidArgument); return; } // if not an aggregation report output, then only convert for the first report if (!args.Aggregation) { TestReportBase testReport = testReports.First(); if (testReport == null) { ProgramExit.Exit(ExitCode.CannotReadFile); return; } // the output JUnit file path must be NOT same as the input file FileInfo fiInput = new FileInfo(testReport.ReportFile); FileInfo fiOutput = new FileInfo(args.JUnitXmlFile); if (fiInput.FullName == fiOutput.FullName) { OutputWriter.WriteLine(Properties.Resources.ErrMsg_JUnit_OutputSameAsInput); ProgramExit.Exit(ExitCode.InvalidArgument); return; } // convert if (!JUnit.Converter.ConvertAndSave(args, testReport)) { ProgramExit.Exit(ExitCode.GeneralError); } else { OutputWriter.WriteLine(Properties.Resources.InfoMsg_JUnit_OutputGenerated, fiOutput.FullName); } } else { // an aggregation report output if (!JUnit.Converter.ConvertAndSaveAggregation(args, testReports)) { ProgramExit.Exit(ExitCode.GeneralError); } else { FileInfo fiOutput = new FileInfo(args.JUnitXmlFile); OutputWriter.WriteLine(Properties.Resources.InfoMsg_JUnit_OutputGenerated, fiOutput.FullName); } } } // output - nunit 3 if ((args.OutputFormats & OutputFormats.NUnit3) == OutputFormats.NUnit3) { } }
// For GUI / API / BPT tests private static IEnumerable <testsuiteProperty> ConvertTestsuiteCommonProperties(TestReportBase testReport) { yield return(new testsuiteProperty(Properties.Resources.PropName_TestingTool, testReport.TestingToolNameVersion)); yield return(new testsuiteProperty(Properties.Resources.PropName_OSInfo, testReport.OSInfo)); yield return(new testsuiteProperty(Properties.Resources.PropName_Locale, testReport.Locale)); yield return(new testsuiteProperty(Properties.Resources.PropName_LoginUser, testReport.LoginUser)); yield return(new testsuiteProperty(Properties.Resources.PropName_CPUInfo, testReport.CPUInfoAndCores)); yield return(new testsuiteProperty(Properties.Resources.PropName_Memory, testReport.TotalMemory)); if (testReport.TestInputParameters != null) { foreach (ParameterType pt in testReport.TestInputParameters) { // sample of property name: // Test input: param1 (System.String) yield return(new testsuiteProperty(Properties.Resources.PropName_Prefix_TestInputParam + pt.NameAndType, pt.value)); } } if (testReport.TestOutputParameters != null) { foreach (ParameterType pt in testReport.TestOutputParameters) { // sample of property name: // Test output: param1 (System.String) yield return(new testsuiteProperty(Properties.Resources.PropName_Prefix_TestOutputParam + pt.NameAndType, pt.value)); } } if (testReport.TestAUTs != null) { int i = 0; foreach (TestedApplicationType aut in testReport.TestAUTs) { i++; string propValue = aut.Name; if (!string.IsNullOrWhiteSpace(aut.Version)) { propValue += string.Format(" {0}", aut.Version); } if (!string.IsNullOrWhiteSpace(aut.Path)) { propValue += string.Format(" ({0})", aut.Path); } yield return(new testsuiteProperty(string.Format("{0} {1}", Properties.Resources.PropName_Prefix_AUT, i), propValue)); } } }