public void DiscoverTests(IEnumerable <string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink) { var validSources = from source in sources where source.EndsWith(StringHelper.GetSearchExpression(), StringComparison.CurrentCultureIgnoreCase) select source; foreach (var source in validSources) { var results = appDomainRunner.ExecuteSpecifications(source); var query = from result in results from @group in result.Examples from example in @group.Examples select example; foreach (var example in query) { var testCase = new TestCase(example.Reason, DefaultTestExecutor.ExecutorUri, source) { CodeFilePath = example.FileName, LineNumber = example.LineNumber }; discoverySink.SendTestCase(testCase); } } }
public int Run() { try { var arguments = Args.Parse <Arguments>(args); var writter = consoleFactory.CreateConsoleWritter(arguments.Colour); if (arguments.Help) { ArgUsage.GetStyledUsage <Arguments>().Write(); return(0); } if (arguments.Version) { writter.WriteInformationLine(Assembly.GetEntryAssembly().GetName().Version.ToString()); return(0); } var consoleFormatter = formatterFactory.CreateConsoleFormatter(arguments.Format, writter); var expressionRunner = expressionFactory.CreateExpressionRunner(arguments.DryRun); var specRunner = runnerFactory.CreateSpecificationRunner(arguments.Parrallel, expressionRunner, finder, consoleFormatter); var files = finder.GetSpecificationFiles(arguments.Path, arguments.Pattern); var appDomain = new SpecificationAppDomain(specRunner); var results = new List <ExpressionResult>(); foreach (var file in files) { results.AddRange(appDomain.ExecuteSpecifications(file, arguments.Example)); } consoleFormatter.WriteSummary(results); reporter.Write(fileSystem.OpenWrite(arguments.Output), results); return(results.HasErrors() ? 1 : 0); } catch (ArgException e) { var consoleFormatter = consoleFactory.CreateConsoleWritter(false); consoleFormatter.WriteInformationLine(e.Message); consoleFormatter.WriteLine(); ArgUsage.GetStyledUsage <Arguments>().Write(); return(1); } catch (Exception e) { var consoleFormatter = consoleFactory.CreateConsoleWritter(false); consoleFormatter.WriteInformationLine(e.ToString().Trim()); return(1); } }
public int Run() { try { var arguments = Args.Parse<Arguments>(args); var writter = consoleFactory.CreateConsoleWritter(arguments.Colour); if (arguments.Help) { ArgUsage.GetStyledUsage<Arguments>().Write(); return 0; } if (arguments.Version) { writter.WriteInformationLine(Assembly.GetEntryAssembly().GetName().Version.ToString()); return 0; } var consoleFormatter = formatterFactory.CreateConsoleFormatter(arguments.Format, writter); var expressionRunner = expressionFactory.CreateExpressionRunner(arguments.DryRun); var specRunner = runnerFactory.CreateSpecificationRunner(arguments.Parrallel, expressionRunner, finder, consoleFormatter); var files = finder.GetSpecificationFiles(arguments.Path, arguments.Pattern); var appDomain = new SpecificationAppDomain(specRunner); var results = new List<ExpressionResult>(); foreach (var file in files) { results.AddRange(appDomain.ExecuteSpecifications(file, arguments.Example)); } consoleFormatter.WriteSummary(results); reporter.Write(fileSystem.OpenWrite(arguments.Output), results); return results.HasErrors() ? 1 : 0; } catch (ArgException e) { var consoleFormatter = consoleFactory.CreateConsoleWritter(false); consoleFormatter.WriteInformationLine(e.Message); consoleFormatter.WriteLine(); ArgUsage.GetStyledUsage<Arguments>().Write(); return 1; } catch (Exception e) { var consoleFormatter = consoleFactory.CreateConsoleWritter(false); consoleFormatter.WriteInformationLine(e.ToString().Trim()); return 1; } }
public void BeforeAll() { var finder = new DefaultSpecificationFinder(new DefaultFileSystem()); var expressionRunner = new DefaultExpressionRunnerFactory().CreateExpressionRunner(false); var formatter = new SilentConsoleFormatter(new DefaultConsoleWritter()); runner = new DefaultSpecificationRunner(expressionRunner, finder, formatter); var location = new Uri(typeof(TestSpecificationConfigurationManager).Assembly.CodeBase).LocalPath; var appDomain = new SpecificationAppDomain(runner); var results = appDomain.ExecuteSpecifications(location); using (var stream = new MemoryStream()) { var reporter = new NUnitSpecificationReporter(); reporter.Write(stream, results); stream.Seek(0, SeekOrigin.Begin); var serializer = new XmlSerializer(typeof(resultType)); using (var reader = XmlReader.Create(stream)) { resultType = (resultType)serializer.Deserialize(reader); } } }
private void RunTest(ITestExecutionRecorder frameworkHandle, string source, string spec = null) { var results = appDomainRunner.ExecuteSpecifications(source, spec); var query = from result in results from @group in result.Examples from example in @group.Examples select example; foreach (var example in query) { var testCase = new TestCase(example.Reason, ExecutorUri, source) { CodeFilePath = source }; frameworkHandle.RecordStart(testCase); var testResult = new TestResult(testCase) { DisplayName = example.Reason, Duration = new TimeSpan(example.ElapsedTime), }; if (example.Status == ResultStatus.Error) { testResult.Outcome = TestOutcome.Failed; testResult.ErrorMessage = example.Message; testResult.ErrorStackTrace = example.StackTrace; } if (example.Status == ResultStatus.Success) { testResult.Outcome = TestOutcome.Passed; } frameworkHandle.RecordEnd(testCase, testResult.Outcome); frameworkHandle.RecordResult(testResult); } }
public void BeforeAll() { var finder = new DefaultSpecificationFinder(new DefaultFileSystem()); var expressionRunner = new DefaultExpressionRunnerFactory().CreateExpressionRunner(false); var formatter = new SilentConsoleFormatter(new DefaultConsoleWritter()); runner = new DefaultSpecificationRunner(expressionRunner, finder, formatter); var location = new Uri(typeof(TestSpecificationConfigurationManager).Assembly.CodeBase).LocalPath; var appDomain = new SpecificationAppDomain(runner); var results = appDomain.ExecuteSpecifications(location); using (var stream = new MemoryStream()) { var reporter = new NUnitSpecificationReporter(); reporter.Write(stream, results); stream.Seek(0, SeekOrigin.Begin); var serializer = new XmlSerializer(typeof(resultType)); using (var reader = XmlReader.Create(stream)) { resultType = (resultType)serializer.Deserialize(reader); } } }