Beispiel #1
0
        public void DiscoverTests(
            IEnumerable <string> sources,
            IDiscoveryContext discoveryContext,
            IMessageLogger logger,
            ITestCaseDiscoverySink discoverySink
            )
        {
            if (sources == null)
            {
                throw new ArgumentNullException(nameof(sources));
            }

            if (discoverySink == null)
            {
                throw new ArgumentNullException(nameof(discoverySink));
            }

            var sourceToProjSettings = RunSettingsUtil.GetSourceToProjSettings(discoveryContext.RunSettings, filterType: _frameworkType);

            if (!sourceToProjSettings.Any())
            {
                return;
            }

            foreach (var testGroup in sources.GroupBy(x => sourceToProjSettings.TryGetValue(x, out PythonProjectSettings project) ? project : null))
            {
                DiscoverTestGroup(testGroup, discoveryContext, logger, discoverySink);
            }
        }
Beispiel #2
0
        private void RunTestCases(
            IEnumerable <TestCase> tests,
            IRunContext runContext,
            IFrameworkHandle frameworkHandle
            )
        {
            bool   codeCoverage = ExecutorService.EnableCodeCoverage(runContext);
            string covPath      = null;

            if (codeCoverage)
            {
                covPath = ExecutorService.GetCoveragePath(tests);
            }
            // .py file path -> project settings
            var sourceToSettings = RunSettingsUtil.GetSourceToProjSettings(runContext.RunSettings, filterType: TestFrameworkType.UnitTest);

            foreach (var testGroup in tests.GroupBy(x => sourceToSettings[x.CodeFilePath]))
            {
                if (_cancelRequested.WaitOne(0))
                {
                    break;
                }

                if (testGroup.Key.TestFramework != TestFrameworkType.UnitTest)
                {
                    continue;
                }

                using (var runner = new TestRunner(
                           frameworkHandle,
                           runContext,
                           testGroup,
                           covPath,
                           testGroup.Key,
                           _app,
                           _cancelRequested
                           )) {
                    runner.Run();
                }
            }

            if (codeCoverage)
            {
                ExecutorService.AttachCoverageResults(frameworkHandle, covPath);
            }
        }
Beispiel #3
0
        public void RunTests(IEnumerable <string> sources, IRunContext runContext, IFrameworkHandle frameworkHandle)
        {
            if (sources == null)
            {
                throw new ArgumentNullException(nameof(sources));
            }

            if (runContext == null)
            {
                throw new ArgumentNullException(nameof(runContext));
            }

            if (frameworkHandle == null)
            {
                throw new ArgumentNullException(nameof(frameworkHandle));
            }

            _cancelRequested.Reset();

            var sourceToProjSettings = RunSettingsUtil.GetSourceToProjSettings(runContext.RunSettings, filterType: TestFrameworkType.UnitTest);
            var testColletion        = new TestCollection();

            foreach (var testGroup in sources.GroupBy(x => sourceToProjSettings[x]))
            {
                var settings = testGroup.Key;

                try {
                    var discovery = DiscovererFactory.GetDiscoverer(settings);
                    discovery.DiscoverTests(testGroup, frameworkHandle, testColletion);
                } catch (Exception ex) {
                    frameworkHandle.SendMessage(TestMessageLevel.Error, ex.Message);
                }

                if (_cancelRequested.WaitOne(0))
                {
                    return;
                }
            }

            RunTestCases(testColletion.Tests, runContext, frameworkHandle);
        }
Beispiel #4
0
        private void RunPytest(
            IEnumerable <TestCase> tests,
            IRunContext runContext,
            IFrameworkHandle frameworkHandle
            )
        {
            var sourceToProjSettings = RunSettingsUtil.GetSourceToProjSettings(runContext.RunSettings, filterType: TestFrameworkType.Pytest);

            foreach (var testGroup in tests.GroupBy(t => sourceToProjSettings.TryGetValue(t.CodeFilePath ?? String.Empty, out PythonProjectSettings proj) ? proj : null))
            {
                if (testGroup.Key == null)
                {
                    Debug.WriteLine("Missing projectSettings for TestCases:");
                    Debug.WriteLine(String.Join(",\n", testGroup));
                }

                if (_cancelRequested.WaitOne(0))
                {
                    break;
                }

                RunTestGroup(testGroup, runContext, frameworkHandle);
            }
        }