コード例 #1
0
 public static TestCase ToTestCase(this VsTestCase vsTestCase)
 {
     var testCase = new TestCase(vsTestCase.FullyQualifiedName, vsTestCase.Source, 
         vsTestCase.DisplayName, vsTestCase.CodeFilePath, vsTestCase.LineNumber);
     testCase.Traits.AddRange(vsTestCase.Traits.Select(ToTrait));
     return testCase;
 }
コード例 #2
0
 private TestCase CreateTestCase(TestCaseDescriptor descriptor)
 {
     var testCase = new TestCase(
         descriptor.FullyQualifiedName, _executable, descriptor.DisplayName, "", 0);
     testCase.Traits.AddRange(GetFinalTraits(descriptor.DisplayName, new List<Trait>()));
     return testCase;
 }
コード例 #3
0
        private void RunAndVerifySingleTest(TestCase testCase, VsTestOutcome expectedOutcome)
        {
            TestExecutor executor = new TestExecutor(TestEnvironment);
            executor.RunTests(testCase.ToVsTestCase().Yield(), MockRunContext.Object, MockFrameworkHandle.Object);

            foreach (VsTestOutcome outcome in Enum.GetValues(typeof(VsTestOutcome)))
            {
                MockFrameworkHandle.Verify(h => h.RecordEnd(It.IsAny<VsTestCase>(), It.Is<VsTestOutcome>(to => to == outcome)),
                    Times.Exactly(outcome == expectedOutcome ? 1 : 0));
            }
        }
コード例 #4
0
        public static TestCase ToTestCase(this VsTestCase vsTestCase)
        {
            var testCase = new TestCase(vsTestCase.FullyQualifiedName, vsTestCase.Source,
                                        vsTestCase.DisplayName, vsTestCase.CodeFilePath, vsTestCase.LineNumber);

            testCase.Traits.AddRange(vsTestCase.Traits.Select(ToTrait));

            var metaDataSerialization = vsTestCase.GetPropertyValue(TestMetaDataProperty);

            if (metaDataSerialization != null)
            {
                testCase.Properties.Add(new TestCaseMetaDataProperty((string)metaDataSerialization));
            }

            return(testCase);
        }
コード例 #5
0
        private TestCase CreateTestCase(TestCaseDescriptor descriptor, List<TestCaseLocation> testCaseLocations)
        {
            TestCaseLocation location = testCaseLocations.FirstOrDefault(
                l => _signatureCreator.GetTestMethodSignatures(descriptor).Any(s => Regex.IsMatch(l.Symbol, s)));

            if (location != null)
            {
                var testCase = new TestCase(
                    descriptor.FullyQualifiedName, _executable, descriptor.DisplayName, location.Sourcefile, (int)location.Line);
                testCase.Traits.AddRange(GetFinalTraits(descriptor.DisplayName, location.Traits));
                return testCase;
            }

            _testEnvironment.LogWarning($"Could not find source location for test {descriptor.FullyQualifiedName}");
            return new TestCase(
                descriptor.FullyQualifiedName, _executable, descriptor.DisplayName, "", 0);
        }
コード例 #6
0
        private ITestsSplitter GetTestsSplitter(TestCase[] testCasesToRun)
        {
            var serializer = new TestDurationSerializer();
            IDictionary<TestCase, int> durations = serializer.ReadTestDurations(testCasesToRun);

            ITestsSplitter splitter;
            if (durations.Count < testCasesToRun.Length)
            {
                splitter = new NumberBasedTestsSplitter(testCasesToRun, _testEnvironment);
                _testEnvironment.DebugInfo("Using splitter based on number of tests");
            }
            else
            {
                splitter = new DurationBasedTestsSplitter(durations, _testEnvironment);
                _testEnvironment.DebugInfo("Using splitter based on test durations");
            }

            return splitter;
        }
コード例 #7
0
        public static VsTestCase ToVsTestCase(this TestCase testCase)
        {
            var vsTestCase = new VsTestCase(testCase.FullyQualifiedName, TestExecutor.ExecutorUri, testCase.Source)
            {
                DisplayName  = testCase.DisplayName,
                CodeFilePath = testCase.CodeFilePath,
                LineNumber   = testCase.LineNumber
            };

            vsTestCase.Traits.AddRange(testCase.Traits.Select(ToVsTrait));

            var property = testCase.Properties.OfType <TestCaseMetaDataProperty>().SingleOrDefault();

            if (property != null)
            {
                vsTestCase.SetPropertyValue(TestMetaDataProperty, property.Serialization);
            }

            return(vsTestCase);
        }
コード例 #8
0
        private TestResult CreateTestResult(int indexOfTestcase)
        {
            int currentLineIndex = indexOfTestcase;

            string line = _consoleOutput[currentLineIndex++];
            string qualifiedTestname = RemovePrefix(line).Trim();
            TestCase testCase = FindTestcase(qualifiedTestname);

            if (currentLineIndex >= _consoleOutput.Count)
            {
                CrashedTestCase = testCase;
                return CreateFailedTestResult(testCase, TimeSpan.FromMilliseconds(0), CrashText, "");
            }

            line = _consoleOutput[currentLineIndex++];

            string errorMsg = "";
            while (!(IsFailedLine(line) || IsPassedLine(line)) && currentLineIndex <= _consoleOutput.Count)
            {
                errorMsg += line + "\n";
                line = currentLineIndex < _consoleOutput.Count ? _consoleOutput[currentLineIndex] : "";
                currentLineIndex++;
            }
            if (IsFailedLine(line))
            {
                ErrorMessageParser parser = new ErrorMessageParser(errorMsg, _baseDir);
                parser.Parse();
                return CreateFailedTestResult(testCase, ParseDuration(line), parser.ErrorMessage, parser.ErrorStackTrace);
            }
            if (IsPassedLine(line))
            {
                return CreatePassedTestResult(testCase, ParseDuration(line));
            }

            CrashedTestCase = testCase;
            string message = CrashText;
            message += errorMsg == "" ? "" : "\nTest output:\n\n" + errorMsg;
            return CreateFailedTestResult(testCase, TimeSpan.FromMilliseconds(0), message, "");
        }
コード例 #9
0
 public TestResult(TestCase testCase)
 {
     TestCase = testCase;
 }
コード例 #10
0
 private TestResult CreateFailedTestResult(TestCase testCase, TimeSpan duration, string errorMessage, string errorStackTrace)
 {
     return new TestResult(testCase)
     {
         ComputerName = Environment.MachineName,
         DisplayName = testCase.DisplayName,
         Outcome = TestOutcome.Failed,
         ErrorMessage = errorMessage,
         ErrorStackTrace = errorStackTrace,
         Duration = duration
     };
 }
コード例 #11
0
 private TestResult CreatePassedTestResult(TestCase testCase, TimeSpan duration)
 {
     return new TestResult(testCase)
     {
         ComputerName = Environment.MachineName,
         DisplayName = testCase.DisplayName,
         Outcome = TestOutcome.Passed,
         Duration = duration
     };
 }