コード例 #1
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));
            }
        }
コード例 #2
0
        private void RunAndVerifySingleTest(TestCase testCase, VsTestOutcome expectedOutcome)
        {
            TestExecutor executor = new TestExecutor(TestEnvironment.Logger, TestEnvironment.Options);

            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));
            }
        }
コード例 #3
0
        private void RunExitCodeTest(string testCaseName, VsTestOutcome outcome)
        {
            string exitCodeTestName = "ExitCode";

            MockOptions.Setup(o => o.ExitCodeTestCase).Returns(exitCodeTestName);

            TestCase testCase = TestDataCreator.GetTestCases(testCaseName).First();

            TestExecutor executor = new TestExecutor(TestEnvironment.Logger, TestEnvironment.Options, MockDebuggerAttacher.Object);

            executor.RunTests(testCase.ToVsTestCase().Yield(), MockRunContext.Object, MockFrameworkHandle.Object);

            MockFrameworkHandle.Verify(h => h.RecordResult(It.Is <VsTestResult>(result =>
                                                                                result.TestCase.FullyQualifiedName == testCaseName &&
                                                                                result.Outcome == outcome
                                                                                )),
                                       Times.Once);

            // ReSharper disable once PossibleNullReferenceException
            string finalName       = exitCodeTestName + "." + Path.GetFileName(testCase.Source).Replace(".", "_");
            bool   outputAvailable = MockOptions.Object.UseNewTestExecutionFramework ||
                                     !MockRunContext.Object.IsBeingDebugged;
            Func <VsTestResult, bool> errorMessagePredicate = outcome == VsTestOutcome.Failed
                ? result => result.ErrorMessage.Contains("Exit code: 1") &&
                                                              (!outputAvailable || result.ErrorMessage.Contains("The result code output")) &&
                                                              !result.ErrorMessage.Contains(StreamingStandardOutputTestResultParser.GtaExitCodeOutputBegin) &&
                                                              !result.ErrorMessage.Contains(StreamingStandardOutputTestResultParser.GtaExitCodeOutputEnd) &&
                                                              !result.ErrorMessage.Contains("Some more output")
                : (Func <VsTestResult, bool>)(result => string.IsNullOrEmpty(result.ErrorMessage) || result.ErrorMessage.Contains("The result code output"));

            MockFrameworkHandle.Verify(h => h.RecordResult(It.Is <VsTestResult>(result =>
                                                                                result.TestCase.FullyQualifiedName == finalName &&
                                                                                result.Outcome == outcome &&
                                                                                errorMessagePredicate(result)
                                                                                )),
                                       Times.Once);

            MockFrameworkHandle.Verify(h => h.RecordResult(It.IsAny <VsTestResult>()), Times.Exactly(2));

            if (!outputAvailable && outcome == VsTestOutcome.Failed)
            {
                MockLogger.Verify(l => l.LogWarning(It.Is <string>(msg => msg.Contains("Result code") &&
                                                                   msg.Contains(SettingsWrapper.OptionUseNewTestExecutionFramework))), Times.Once);
            }

            MockLogger.Verify(l => l.DebugWarning(It.Is <string>(msg => msg.Contains("main method") && msg.Contains("exit code"))), Times.Never);
        }
コード例 #4
0
        public void WriteResultSummary(VsTestOutcome outcome, Xunit.ExecutionSummary executionSummary)
        {
            if (!inDocument)
            {
                throw new InvalidOperationException("WriteStartDocument() not called");
            }

            xml.WriteStartElement("ResultSummary", XmlNamespace);
            xml.WriteAttributeString("outcome", VsTestOutcomeHelper.GetOutcomeString(outcome));

            xml.WriteStartElement("Counters", XmlNamespace);
            xml.WriteAttributeString("total", executionSummary.Total.ToString(CultureInfo.InvariantCulture));
            xml.WriteAttributeString("executed", (executionSummary.Total - executionSummary.Skipped).ToString(CultureInfo.InvariantCulture));
            xml.WriteAttributeString("passed", (executionSummary.Total - (executionSummary.Failed + executionSummary.Skipped)).ToString(CultureInfo.InvariantCulture));
            xml.WriteAttributeString("inconclusive", executionSummary.Skipped.ToString(CultureInfo.InvariantCulture));
            xml.WriteAttributeString("failed", executionSummary.Failed.ToString(CultureInfo.InvariantCulture));
            xml.WriteAttributeString("error", executionSummary.Errors.ToString(CultureInfo.InvariantCulture));
            xml.WriteEndElement(); // Counters

            xml.WriteEndElement(); // ResultSummary
        }
コード例 #5
0
        protected void RunMemoryLeakTest(string executable, string testCaseName, VsTestOutcome testOutcome, VsTestOutcome leakCheckOutcome, Func <string, bool> errorMessagePredicate)
        {
            string exitCodeTestName = "MemoryLeakTest";

            MockOptions.Setup(o => o.ExitCodeTestCase).Returns(exitCodeTestName);
            MockOptions.Setup(o => o.AdditionalTestExecutionParam).Returns("-is_run_by_gta");

            var testCases = new GoogleTestDiscoverer(MockLogger.Object, TestEnvironment.Options,
                                                     new ProcessExecutorFactory(), new DefaultDiaResolverFactory()).GetTestsFromExecutable(executable);
            var testCase = testCases.Single(tc => tc.DisplayName == testCaseName);

            var executor = new TestExecutor(TestEnvironment.Logger, TestEnvironment.Options, MockDebuggerAttacher.Object);

            executor.RunTests(testCase.Yield().Select(tc => tc.ToVsTestCase()), MockRunContext.Object, MockFrameworkHandle.Object);

            var invocations = new List <IInvocation>();

            foreach (var invocation in MockFrameworkHandle.Invocations)
            {
                invocations.Add(invocation);
            }

            MockFrameworkHandle.Verify(h => h.RecordResult(It.Is <VsTestResult>(result =>
                                                                                result.TestCase.FullyQualifiedName == testCaseName &&
                                                                                result.Outcome == testOutcome
                                                                                )),
                                       Times.Once);

            MockFrameworkHandle.Verify(h => h.RecordResult(It.Is <VsTestResult>(result =>
                                                                                result.TestCase.FullyQualifiedName.StartsWith("MemoryLeakTest") &&
                                                                                result.Outcome == leakCheckOutcome &&
                                                                                (result.ErrorMessage == null || !result.ErrorMessage.Contains(StreamingStandardOutputTestResultParser.GtaExitCodeOutputBegin)) &&
                                                                                (result.ErrorMessage == null || !result.ErrorMessage.Contains(StreamingStandardOutputTestResultParser.GtaExitCodeOutputEnd)) &&
                                                                                errorMessagePredicate(result.ErrorMessage)
                                                                                )),
                                       Times.Once);

            MockLogger.Verify(l => l.DebugWarning(It.Is <string>(msg => msg.Contains("main method") && msg.Contains("exit code"))), Times.Never);
        }
コード例 #6
0
 public long this[Microsoft.VisualStudio.TestPlatform.ObjectModel.TestOutcome testOutcome]
 {
     get { return(0); }
 }