예제 #1
0
        private static void RunLocally(IFrameworkHandle frameworkHandle, IGrouping <string, TestCase> source)
        {
            var discoverer = new TestDiscoverer();
            var tests2     = discoverer.LoadFromSources(new[] { source.Key },
                                                        x => frameworkHandle.SendMessage(TestMessageLevel.Informational, x));

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

            var runner = new TestRunner(discoverer);

            runner.Load(new[] { tests2[0].Type.Assembly }).GetAwaiter().GetResult();

            foreach (var testCase in source)
            {
                var testClassName = (string)testCase.GetPropertyValue(Constants.TestClassProperty);
                var testName      = (string)testCase.GetPropertyValue(Constants.TestMethodProperty);

                var method = discoverer.Get(testClassName, testName);
                if (method == null)
                {
                    frameworkHandle.RecordResult(new TestResult(testCase)
                    {
                        Outcome = TestOutcome.NotFound
                    });
                    continue;
                }

                RunTestMethod(frameworkHandle, testCase, runner, method);
            }

            runner.Shutdown().GetAwaiter().GetResult();
        }
예제 #2
0
        public void DiscoverTests(IEnumerable <string> sources, IDiscoveryContext discoveryContext,
                                  IMessageLogger logger,
                                  ITestCaseDiscoverySink discoverySink)
        {
            var uri = new Uri(Constants.ExecutorUri);
            var foundTestClasses =
                _discoverer.LoadFromSources(
                    sources,
                    msg => logger.SendMessage(TestMessageLevel.Error, msg)
                    );

            logger.SendMessage(TestMessageLevel.Informational, "Finding tests based on Coderr.Tests");
            foreach (var testClass in foundTestClasses)
            {
                foreach (var method in testClass.Methods)
                {
                    var name     = $"{testClass.Type.FullName}.{method.Name}";
                    var testCase = new TestCase(name, uri, testClass.Source)
                    {
                        DisplayName = method.Name.Replace("_", " "),
                    };

                    testCase.SetPropertyValue(Constants.TestClassProperty, testClass.Type.FullName);
                    testCase.SetPropertyValue(Constants.TestMethodProperty, method.Name);
                    discoverySink.SendTestCase(testCase);
                }
            }
        }