Example #1
0
        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()
                );
        }
Example #2
0
        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);

            RunSettingsHelper.ReadRunSettings(discoveryContext?.RunSettings?.SettingsXml);
            if (!ValidateRuntimeFramework())
            {
                return;
            }

            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.CollectSourceInformation,

                // 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)
                          );
        }
Example #3
0
        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());
        }