void ITestExecutor.RunTests(IEnumerable <string> sources, IRunContext runContext, IFrameworkHandle frameworkHandle) { Guard.ArgumentNotNull("sources", sources); var stopwatch = Stopwatch.StartNew(); var logger = new LoggerHelper(frameworkHandle, stopwatch); #if NET35 || NETCOREAPP1_0 // Reads settings like disabling appdomains, parallel etc. // Do this first before invoking any thing else to ensure correct settings for the run RunSettingsHelper.ReadRunSettings(runContext?.RunSettings?.SettingsXml); #endif // In this case, we need to go thru the files manually if (ContainsAppX(sources)) { #if WINDOWS_UAP var sourcePath = Windows.ApplicationModel.Package.Current.InstalledLocation.Path; #elif NETCOREAPP1_0 var sourcePath = Directory.GetCurrentDirectory(); #else var sourcePath = Environment.CurrentDirectory; #endif sources = Directory.GetFiles(sourcePath, "*.dll") .Where(file => !platformAssemblies.Contains(Path.GetFileName(file))) .ToList(); ((List <string>)sources).AddRange(Directory.GetFiles(sourcePath, "*.exe") .Where(file => !platformAssemblies.Contains(Path.GetFileName(file)))); } RunTests(runContext, frameworkHandle, logger, () => GetTests(sources, logger, runContext, RunSettingsHelper.DesignMode)); }
void ITestExecutor.RunTests(IEnumerable <TestCase> tests, IRunContext runContext, IFrameworkHandle frameworkHandle) { Guard.ArgumentNotNull("tests", tests); Guard.ArgumentValid("tests", "AppX not supported in this overload", !ContainsAppX(tests.Select(t => t.Source))); var stopwatch = Stopwatch.StartNew(); var logger = new LoggerHelper(frameworkHandle, stopwatch); #if NET452 || NETCOREAPP1_0 RunSettingsHelper.ReadRunSettings(runContext?.RunSettings?.SettingsXml); #endif // In the context of Run Specific tests, commandline runner doesn't require source information or // serialized xunit test case property var testPlatformContext = new TestPlatformContext { RequireSourceInformation = RunSettingsHelper.CollectSourceInformation, RequireXunitTestProperty = RunSettingsHelper.DesignMode }; RunTests( runContext, frameworkHandle, logger, testPlatformContext, () => tests.GroupBy(testCase => testCase.Source) .Select(group => new AssemblyRunInfo { AssemblyFileName = group.Key, Configuration = LoadConfiguration(group.Key), TestCases = group.ToList() }) .ToList() ); }
void ITestDiscoverer.DiscoverTests(IEnumerable <string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink) { Guard.ArgumentNotNull("sources", sources); Guard.ArgumentNotNull("logger", logger); Guard.ArgumentNotNull("discoverySink", discoverySink); Guard.ArgumentValid("sources", "AppX not supported for discovery", !ContainsAppX(sources)); var stopwatch = Stopwatch.StartNew(); var loggerHelper = new LoggerHelper(logger, stopwatch); #if NET452 || NETCOREAPP1_0 // Reads settings like disabling appdomains, parallel etc. // Do this first before invoking any thing else to ensure correct settings for the run RunSettingsHelper.ReadRunSettings(discoveryContext?.RunSettings?.SettingsXml); #endif var testPlatformContext = new TestPlatformContext { // Discovery from command line (non designmode) never requires source information // since there is no session or command line runner doesn't send back VSTestCase objects // back to adapter. RequireSourceInformation = RunSettingsHelper.DesignMode, // Command line runner could request for Discovery in case of running specific tests. We need // the XunitTestCase serialized in this scenario. RequireXunitTestProperty = true }; DiscoverTests(sources, loggerHelper, testPlatformContext, (source, discoverer, discoveryOptions) => new VsDiscoverySink(source, discoverer, loggerHelper, discoverySink, discoveryOptions, testPlatformContext, () => cancelled) ); }
void ITestExecutor.RunTests(IEnumerable <string> sources, IRunContext runContext, IFrameworkHandle frameworkHandle) { Guard.ArgumentNotNull("sources", sources); var stopwatch = Stopwatch.StartNew(); var logger = new LoggerHelper(frameworkHandle, stopwatch); #if NET452 || NETCOREAPP1_0 RunSettingsHelper.ReadRunSettings(runContext?.RunSettings?.SettingsXml); if (!ValidateRuntimeFramework()) { return; } #endif // In the context of Run All tests, commandline runner doesn't require source information or // serialized xunit test case property var testPlatformContext = new TestPlatformContext { RequireSourceInformation = RunSettingsHelper.CollectSourceInformation, RequireXunitTestProperty = RunSettingsHelper.DesignMode }; // In this case, we need to go thru the files manually if (ContainsAppX(sources)) { #if WINDOWS_UAP var sourcePath = Windows.ApplicationModel.Package.Current.InstalledLocation.Path; #elif NETCOREAPP1_0 var sourcePath = Directory.GetCurrentDirectory(); #else var sourcePath = Environment.CurrentDirectory; #endif sources = Directory.GetFiles(sourcePath, "*.dll") .Where(file => !platformAssemblies.Contains(Path.GetFileName(file))) .ToList(); ((List <string>)sources).AddRange(Directory.GetFiles(sourcePath, "*.exe") .Where(file => !platformAssemblies.Contains(Path.GetFileName(file)))); } RunTests(runContext, frameworkHandle, logger, testPlatformContext, () => sources.Select(source => { var assemblyFileName = GetAssemblyFileName(source); return(new AssemblyRunInfo { AssemblyFileName = assemblyFileName, Configuration = LoadConfiguration(assemblyFileName), TestCases = null // PERF: delay the discovery until we actually require it in RunTestsInAssembly }); }).ToList()); }
void RunTests(IRunContext runContext, IFrameworkHandle frameworkHandle, LoggerHelper logger, Func <List <AssemblyRunInfo> > testCaseAccessor) { Guard.ArgumentNotNull("runContext", runContext); Guard.ArgumentNotNull("frameworkHandle", frameworkHandle); try { RemotingUtility.CleanUpRegisteredChannels(); #if NET35 || NETCOREAPP1_0 // Reads settings like disabling appdomains, parallel etc. // Do this first before invoking any thing else to ensure correct settings for the run RunSettingsHelper.ReadRunSettings(runContext?.RunSettings?.SettingsXml); #endif cancelled = false; var assemblies = testCaseAccessor(); var parallelizeAssemblies = !RunSettingsHelper.DisableParallelization && assemblies.All(runInfo => runInfo.Configuration.ParallelizeAssemblyOrDefault); var reporterMessageHandler = MessageSinkWithTypesAdapter.Wrap(GetRunnerReporter(assemblies.Select(ari => ari.AssemblyFileName)) .CreateMessageHandler(new VisualStudioRunnerLogger(logger))); using (AssemblyHelper.SubscribeResolve()) if (parallelizeAssemblies) { assemblies .Select(runInfo => RunTestsInAssemblyAsync(runContext, frameworkHandle, logger, reporterMessageHandler, runInfo)) .ToList() .ForEach(@event => @event.WaitOne()); } else { assemblies .ForEach(runInfo => RunTestsInAssembly(runContext, frameworkHandle, logger, reporterMessageHandler, runInfo)); } } catch (Exception ex) { logger.LogError("Catastrophic failure: {0}", ex); } }
void ITestDiscoverer.DiscoverTests(IEnumerable <string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink) { Guard.ArgumentNotNull("sources", sources); Guard.ArgumentNotNull("logger", logger); Guard.ArgumentNotNull("discoverySink", discoverySink); Guard.ArgumentValid("sources", "AppX not supported for discovery", !ContainsAppX(sources)); var stopwatch = Stopwatch.StartNew(); var loggerHelper = new LoggerHelper(logger, stopwatch); #if NET35 || NETCOREAPP1_0 // Reads settings like disabling appdomains, parallel etc. // Do this first before invoking any thing else to ensure correct settings for the run RunSettingsHelper.ReadRunSettings(discoveryContext?.RunSettings?.SettingsXml); #endif DiscoverTests(sources, loggerHelper, (source, discoverer, discoveryOptions) => new VsDiscoverySink(source, discoverer, loggerHelper, discoverySink, discoveryOptions, RunSettingsHelper.DesignMode, () => cancelled) ); }
void ITestExecutor.RunTests(IEnumerable <TestCase> tests, IRunContext runContext, IFrameworkHandle frameworkHandle) { Guard.ArgumentNotNull("tests", tests); Guard.ArgumentValid("tests", "AppX not supported in this overload", !ContainsAppX(tests.Select(t => t.Source))); var stopwatch = Stopwatch.StartNew(); var logger = new LoggerHelper(frameworkHandle, stopwatch); #if NET35 || NETCOREAPP1_0 // Reads settings like disabling appdomains, parallel etc. // Do this first before invoking any thing else to ensure correct settings for the run RunSettingsHelper.ReadRunSettings(runContext?.RunSettings?.SettingsXml); #endif RunTests( runContext, frameworkHandle, logger, () => tests.GroupBy(testCase => testCase.Source) .Select(group => new AssemblyRunInfo { AssemblyFileName = group.Key, Configuration = LoadConfiguration(group.Key), TestCases = group.ToList() }) .ToList() ); }
void DiscoverTests <TVisitor>(IRunSettings runSettings, IEnumerable <string> sources, LoggerHelper logger, Func <string, ITestFrameworkDiscoverer, ITestFrameworkDiscoveryOptions, TVisitor> visitorFactory, Action <string, ITestFrameworkDiscoverer, ITestFrameworkDiscoveryOptions, TVisitor> visitComplete = null) where TVisitor : IVsDiscoverySink, IDisposable { try { RemotingUtility.CleanUpRegisteredChannels(); using (AssemblyHelper.SubscribeResolve()) { #if NET35 || NETCOREAPP1_0 // Reads settings like disabling appdomains, parallel etc. // Do this first before invoking any thing else to ensure correct settings for the run RunSettingsHelper.ReadRunSettings(runSettings?.SettingsXml); #endif var reporterMessageHandler = GetRunnerReporter(sources).CreateMessageHandler(new VisualStudioRunnerLogger(logger)); foreach (var assemblyFileNameCanBeWithoutAbsolutePath in sources) { var assemblyFileName = assemblyFileNameCanBeWithoutAbsolutePath; #if !PLATFORM_DOTNET assemblyFileName = Path.GetFullPath(assemblyFileNameCanBeWithoutAbsolutePath); #endif var assembly = new XunitProjectAssembly { AssemblyFilename = assemblyFileName }; var configuration = LoadConfiguration(assemblyFileName); var fileName = Path.GetFileNameWithoutExtension(assemblyFileName); var shadowCopy = configuration.ShadowCopyOrDefault; try { if (cancelled) { break; } if (!IsXunitTestAssembly(assemblyFileName)) { if (configuration.DiagnosticMessagesOrDefault) { logger.Log("Skipping: {0} (no reference to xUnit.net)", fileName); } } else { var diagnosticSink = new DiagnosticMessageSink(logger, fileName, configuration.DiagnosticMessagesOrDefault); using (var framework = new XunitFrontController(AppDomainDefaultBehavior, assemblyFileName: assemblyFileName, configFileName: null, shadowCopy: shadowCopy, diagnosticMessageSink: MessageSinkAdapter.Wrap(diagnosticSink))) { var targetFramework = framework.TargetFramework; if (targetFramework.StartsWith("MonoTouch", StringComparison.OrdinalIgnoreCase) || targetFramework.StartsWith("MonoAndroid", StringComparison.OrdinalIgnoreCase) || targetFramework.StartsWith("Xamarin.iOS", StringComparison.OrdinalIgnoreCase)) { if (configuration.DiagnosticMessagesOrDefault) { logger.Log("Skipping: {0} (unsupported target framework '{1}')", fileName, targetFramework); } } else { var discoveryOptions = TestFrameworkOptions.ForDiscovery(configuration); using (var visitor = visitorFactory(assemblyFileName, framework, discoveryOptions)) { reporterMessageHandler.OnMessage(new TestAssemblyDiscoveryStarting(assembly, framework.CanUseAppDomains && AppDomainDefaultBehavior != AppDomainSupport.Denied, shadowCopy, discoveryOptions)); framework.Find(includeSourceInformation: true, discoveryMessageSink: visitor, discoveryOptions: discoveryOptions); var totalTests = visitor.Finish(); visitComplete?.Invoke(assemblyFileName, framework, discoveryOptions, visitor); reporterMessageHandler.OnMessage(new TestAssemblyDiscoveryFinished(assembly, discoveryOptions, totalTests, totalTests)); } } } } } catch (Exception e) { var ex = e.Unwrap(); var fileNotFound = ex as FileNotFoundException; #if !PLATFORM_DOTNET var fileLoad = ex as FileLoadException; #endif if (ex is InvalidOperationException) { logger.LogWarning("Skipping: {0} ({1})", fileName, ex.Message); } else if (fileNotFound != null) { logger.LogWarning("Skipping: {0} (could not find dependent assembly '{1}')", fileName, Path.GetFileNameWithoutExtension(fileNotFound.FileName)); } #if !PLATFORM_DOTNET else if (fileLoad != null) { logger.LogWarning("Skipping: {0} (could not find dependent assembly '{1}')", fileName, Path.GetFileNameWithoutExtension(fileLoad.FileName)); } #endif else { logger.LogWarning("Exception discovering tests from {0}: {1}", fileName, ex); } } } } } catch (Exception e) { logger.LogWarning("Exception discovering tests: {0}", e.Unwrap()); } }