public void ParseLine_RUN_RaisesTestStartedEvent()
        {
            ITestSuite suite;
            CreateMockSuite(out suite);
            var parserUnderTest = new GTestRunOutputParser(suite, new Mock<ITestLogger>().Object);
            ParserValidator validator = new ParserValidator(parserUnderTest);

            parserUnderTest.ParseLine("[ RUN      ] Test.Test");

            Assert.True(validator.TestStarted);
        }
        public void ParseLine_OK_RaisesFinishedEventWithPassedResult()
        {
            ITestSuite suite;
            CreateMockSuite(out suite);
            var parserUnderTest = new GTestRunOutputParser(suite, new Mock<ITestLogger>().Object);
            ParserValidator validator = new ParserValidator(parserUnderTest);

            parserUnderTest.ParseLine("[       OK ] Test.Test (10ms)");

            Assert.True(validator.TestFinished);
            Assert.NotNull(validator.FinishResult);
            Assert.AreEqual(TestStatus.Passed, validator.FinishResult.Outcome);
        }
        public void ParseLine_FAILED_TestWithParams_RaisesFinishedEventWithFailedResult()
        {
            ITestSuite suite;
            CreateMockSuite(out suite);
            var parserUnderTest = new GTestRunOutputParser(suite, new Mock<ITestLogger>().Object);
            ParserValidator validator = new ParserValidator(parserUnderTest);

            parserUnderTest.ParseLine("[  FAILED  ] Test.Test, where GetParam() = \"Test\" (10 ms)");

            Assert.True(validator.TestFinished);
            Assert.NotNull(validator.FinishResult);
            Assert.AreEqual(TestStatus.Failed, validator.FinishResult.Outcome);
        }
        public void ParseLine_FAILED_EndResult_RaisesNoEvents()
        {
            ITestSuite suite;
            CreateMockSuite(out suite);
            var parserUnderTest = new GTestRunOutputParser(suite, new Mock<ITestLogger>().Object);
            ParserValidator validator = new ParserValidator(parserUnderTest);

            parserUnderTest.ParseLine("[  FAILED  ] 1 test, listed below:");
            parserUnderTest.ParseLine("[  FAILED  ] Test.Test");

            Assert.False(validator.TestDiscovered);
            Assert.False(validator.TestStarted);
            Assert.False(validator.TestFinished);
        }
示例#5
0
        private void Run(RunArgs args)
        {
            _logger.Information(string.Format("Beginning test run of {0}...", args.Suite.RunTarget));
            GTestRunOutputParser parser = new GTestRunOutputParser(args.Suite, _logger);
            DataReceivedEventHandler handler = (sender, eventArgs) => parser.ParseLine(eventArgs.Data);
            parser.TestFinished += OnTestCompleted;

            foreach (var testCase in args.Suite.TestCases)
            {
                foreach (var test in testCase.Tests)
                {
                    if(test.Name.StartsWith("DISABLED_"))
                    {
                        TestResult result = new TestResult() {Outcome = TestStatus.Ignored};
                        test.Completed(result);
                        OnTestCompleted(test, result);
                    }
                }
            }

            ProcessStartInfo gtestProcInfo = new ProcessStartInfo(args.Suite.RunTarget)
                {
                    RedirectStandardOutput = true,
                    CreateNoWindow = true,
                    UseShellExecute = false
                };
            if (!string.IsNullOrEmpty(args.Filter))
            {
                gtestProcInfo.Arguments = string.Format("--gtest_filter={0}", args.Filter);
            }
            else
            {
                List<string> caseNames = new List<string>();
                foreach (var testCase in args.Suite.TestCases)
                {
                    foreach (var test in testCase.Tests)
                    {
                        caseNames.Add(test.FullyQualifiedName);
                    }
                }
                if (caseNames.Count > 0)
                {
                    gtestProcInfo.Arguments = string.Format("--gtest_filter={0}", string.Join(":", caseNames.ToArray()));
                }
            }

            Process gtestProc = new Process();
            gtestProc.StartInfo = gtestProcInfo;
            gtestProc.OutputDataReceived += handler;

            gtestProc.Start();
            gtestProc.BeginOutputReadLine();

            while (!gtestProc.HasExited)
            {
                gtestProc.WaitForExit(0);
                if (_worker.CancellationPending)
                {
                    gtestProc.Close();
                    break;
                }
            }

            gtestProc.WaitForExit();

            gtestProc.OutputDataReceived -= handler;
        }