static XElement ExecuteAssembly(object consoleLock, string defaultDirectory, XunitProjectAssembly assembly, bool needsXml, bool teamCity, bool appVeyor, bool?parallelizeTestCollections, int?maxThreadCount, XunitFilters filters) { if (cancel) { return(null); } var assemblyElement = needsXml ? new XElement("assembly") : null; try { if (!ValidateFileExists(consoleLock, assembly.AssemblyFilename) || !ValidateFileExists(consoleLock, assembly.ConfigFilename)) { return(null); } var discoveryOptions = new XunitDiscoveryOptions(assembly.Configuration); var executionOptions = new XunitExecutionOptions(assembly.Configuration); if (maxThreadCount.HasValue) { executionOptions.MaxParallelThreads = maxThreadCount.GetValueOrDefault(); } if (parallelizeTestCollections.HasValue) { executionOptions.DisableParallelization = !parallelizeTestCollections.GetValueOrDefault(); } lock (consoleLock) { if (assembly.Configuration.DiagnosticMessages) { Console.WriteLine("Discovering: {0} (method display = {1}, parallel test collections = {2}, max threads = {3})", Path.GetFileNameWithoutExtension(assembly.AssemblyFilename), discoveryOptions.MethodDisplay, !executionOptions.DisableParallelization, executionOptions.MaxParallelThreads); } else { Console.WriteLine("Discovering: {0}", Path.GetFileNameWithoutExtension(assembly.AssemblyFilename)); } } using (var controller = new XunitFrontController(assembly.AssemblyFilename, assembly.ConfigFilename, assembly.ShadowCopy)) using (var discoveryVisitor = new TestDiscoveryVisitor()) { controller.Find(includeSourceInformation: false, messageSink: discoveryVisitor, discoveryOptions: discoveryOptions); discoveryVisitor.Finished.WaitOne(); lock (consoleLock) Console.WriteLine("Discovered: {0}", Path.GetFileNameWithoutExtension(assembly.AssemblyFilename)); var resultsVisitor = CreateVisitor(consoleLock, defaultDirectory, assemblyElement, teamCity, appVeyor); var filteredTestCases = discoveryVisitor.TestCases.Where(filters.Filter).ToList(); if (filteredTestCases.Count == 0) { lock (consoleLock) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("ERROR: {0} has no tests to run", Path.GetFileNameWithoutExtension(assembly.AssemblyFilename)); Console.ForegroundColor = ConsoleColor.Gray; } } else { controller.RunTests(filteredTestCases, resultsVisitor, executionOptions); resultsVisitor.Finished.WaitOne(); } } } catch (Exception ex) { Console.WriteLine("{0}: {1}", ex.GetType().FullName, ex.Message); failed = true; } return(assemblyElement); }
protected virtual XElement ExecuteAssembly(string assemblyFileName, string configFileName, TestAssemblyConfiguration configuration) { if (cancel) { return(null); } var assemblyElement = CreateAssemblyXElement(); try { var discoveryOptions = new XunitDiscoveryOptions(configuration); var executionOptions = new XunitExecutionOptions(configuration); if (maxParallelThreads.HasValue) { executionOptions.MaxParallelThreads = maxParallelThreads.GetValueOrDefault(); } if (parallelizeTestCollections.HasValue) { executionOptions.DisableParallelization = !parallelizeTestCollections.GetValueOrDefault(); } if (configuration.DiagnosticMessages) { Log.LogMessage(MessageImportance.High, " Discovering: {0} (method display = {1}, parallel test collections = {2}, max threads = {3})", Path.GetFileNameWithoutExtension(assemblyFileName), discoveryOptions.MethodDisplay, !executionOptions.DisableParallelization, executionOptions.MaxParallelThreads); } else { Log.LogMessage(MessageImportance.High, " Discovering: {0}", Path.GetFileNameWithoutExtension(assemblyFileName)); } using (var controller = CreateFrontController(assemblyFileName, configFileName)) using (var discoveryVisitor = new TestDiscoveryVisitor()) { controller.Find(includeSourceInformation: false, messageSink: discoveryVisitor, discoveryOptions: discoveryOptions); discoveryVisitor.Finished.WaitOne(); Log.LogMessage(MessageImportance.High, " Discovered: {0}", Path.GetFileNameWithoutExtension(assemblyFileName)); using (var resultsVisitor = CreateVisitor(assemblyFileName, assemblyElement)) { var filteredTestCases = discoveryVisitor.TestCases.Where(Filters.Filter).ToList(); if (filteredTestCases.Count == 0) { Log.LogError("{0} has no tests to run", Path.GetFileNameWithoutExtension(assemblyFileName)); ExitCode = 1; } else { controller.RunTests(filteredTestCases, resultsVisitor, executionOptions); resultsVisitor.Finished.WaitOne(); if (resultsVisitor.Failed != 0) { ExitCode = 1; } } } } } catch (Exception ex) { var e = ex; while (e != null) { Log.LogError("{0}: {1}", e.GetType().FullName, e.Message); foreach (var stackLine in e.StackTrace.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)) { Log.LogError(stackLine); } e = e.InnerException; } ExitCode = -1; } return(assemblyElement); }
/// <summary> /// Starts the process of finding all xUnit.net v2 tests in a class. /// </summary> /// <param name="typeName">The fully qualified type name to find tests in.</param> /// <param name="includeSourceInformation">Whether to include source file information, if possible.</param> /// <param name="messageSink">The message sink to report results back to.</param> /// <param name="options">The options used by the test framework during discovery.</param> public void Find(string typeName, bool includeSourceInformation, IMessageSink messageSink, XunitDiscoveryOptions options) { discoverer.Find(typeName, includeSourceInformation, messageSink, options); }
/// <summary> /// Starts the process of finding all xUnit.net v2 tests in an assembly. /// </summary> /// <param name="includeSourceInformation">Whether to include source file information, if possible.</param> /// <param name="messageSink">The message sink to report results back to.</param> /// <param name="options">The options used by the test framework during discovery.</param> public void Find(bool includeSourceInformation, IMessageSink messageSink, XunitDiscoveryOptions options) { discoverer.Find(includeSourceInformation, messageSink, options); }
XElement ExecuteAssembly(object consoleLock, string defaultDirectory, XunitProjectAssembly assembly, bool needsXml, string visitor, bool?parallelizeTestCollections, int?maxThreadCount, XunitFilters filters, bool designTime, bool listTestCases, IReadOnlyList <string> designTimeFullyQualifiedNames) { if (cancel) { return(null); } var assemblyElement = needsXml ? new XElement("assembly") : null; try { var discoveryOptions = new XunitDiscoveryOptions(assembly.Configuration); var executionOptions = new XunitExecutionOptions(assembly.Configuration); if (maxThreadCount.HasValue) { executionOptions.MaxParallelThreads = maxThreadCount.GetValueOrDefault(); } if (parallelizeTestCollections.HasValue) { executionOptions.DisableParallelization = !parallelizeTestCollections.GetValueOrDefault(); } lock (consoleLock) { if (assembly.Configuration.DiagnosticMessages) { Console.WriteLine("Discovering: {0} (method display = {1}, parallel test collections = {2}, max threads = {3})", Path.GetFileNameWithoutExtension(assembly.AssemblyFilename), discoveryOptions.MethodDisplay, !executionOptions.DisableParallelization, executionOptions.MaxParallelThreads); } else { Console.WriteLine("Discovering: {0}", Path.GetFileNameWithoutExtension(assembly.AssemblyFilename)); } } using (var controller = new XunitFrontController(assembly.AssemblyFilename, assembly.ConfigFilename, assembly.ShadowCopy)) using (var discoveryVisitor = new TestDiscoveryVisitor()) { controller.Find(includeSourceInformation: false, messageSink: discoveryVisitor, discoveryOptions: discoveryOptions); discoveryVisitor.Finished.WaitOne(); IDictionary <ITestCase, VsTestCase> vsTestcases = null; if (designTime) { vsTestcases = DesignTimeTestConverter.Convert(discoveryVisitor.TestCases); } lock (consoleLock) Console.WriteLine("Discovered: {0}", Path.GetFileNameWithoutExtension(assembly.AssemblyFilename)); if (listTestCases) { lock (consoleLock) { if (designTime) { var sink = (ITestDiscoverySink)_services.GetService(typeof(ITestDiscoverySink)); foreach (var testcase in vsTestcases.Values) { if (sink != null) { sink.SendTest(testcase); } Console.WriteLine(testcase.FullyQualifiedName); } } else { foreach (var testcase in discoveryVisitor.TestCases) { Console.WriteLine(testcase.DisplayName); } } } return(assemblyElement); } var resultsVisitor = CreateVisitor(consoleLock, defaultDirectory, assemblyElement, visitor); if (designTime) { var sink = (ITestExecutionSink)_services.GetService(typeof(ITestExecutionSink)); resultsVisitor = new DesignTimeExecutionVisitor( sink, vsTestcases, resultsVisitor); } IList <ITestCase> filteredTestCases; if (!designTime || designTimeFullyQualifiedNames.Count == 0) { filteredTestCases = discoveryVisitor.TestCases.Where(filters.Filter).ToList(); } else { filteredTestCases = (from t in vsTestcases where designTimeFullyQualifiedNames.Contains(t.Value.FullyQualifiedName) select t.Key) .ToList(); } if (filteredTestCases.Count == 0) { lock (consoleLock) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("ERROR: {0} has no tests to run", Path.GetFileNameWithoutExtension(assembly.AssemblyFilename)); Console.ForegroundColor = ConsoleColor.Gray; } } else { controller.RunTests(filteredTestCases, resultsVisitor, executionOptions); resultsVisitor.Finished.WaitOne(); } } } catch (Exception ex) { Console.WriteLine("{0}: {1}", ex.GetType().FullName, ex.Message); failed = true; } return(assemblyElement); }
/// <summary> /// Starts the process of running all the xUnit.net v2 tests in the assembly. /// </summary> /// <param name="messageSink">The message sink to report results back to.</param> /// <param name="discoveryOptions">The options to be used during test discovery.</param> /// <param name="executionOptions">The options to be used during test execution.</param> public void Run(IMessageSink messageSink, XunitDiscoveryOptions discoveryOptions, XunitExecutionOptions executionOptions) { executor.RunAll(messageSink, discoveryOptions, executionOptions); }