Пример #1
0
        private void OnTestCase(TestCase testCase)
        {
            _logger.LogDebug("Starting processing test case [{0}]", testCase.Id);
            var isMuted = testCase.Contains(".muted");

            if (isMuted)
            {
                _logger.LogDebug("Test is muted.");
            }

            TestCaseResult testResult = new TestCaseResult(testCase, isMuted);

            _results.Add(testResult);

            var testCaseContext = _testCaseContextFactory.CreateContext(testCase, Options);

            try
            {
                var descriptionWriter = new XDocumentDescriptionWriter(testCaseContext.Logger);
                if (_customTestSessions != null)
                {
                    foreach (var session in _customTestSessions)
                    {
                        session.OnBegin(testCaseContext);
                    }
                }

                ITestCaseProcessor processor = null;
                try
                {
                    processor = _testCaseProcessorFactory.GetProcessor(testCase);
                    processor.Process(testCaseContext);
                }
                catch (Exception ex)
                {
                    testCaseContext.Logger.LogError(ex, "an error occured");
                    testResult.MarkAsFailed(ex);
                }
                finally
                {
                    if (processor != null)
                    {
                        _testCaseProcessorFactory.Release(processor);
                    }
                }

                try
                {
                    testResult.Description = testCaseContext.DescriptionWriter.GetContent();
                }
                catch (Exception ex)
                {
                    testCaseContext.Logger.LogError(ex, "an error occured while getting test case description");
                }

                if (_customTestSessions != null)
                {
                    foreach (var session in _customTestSessions)
                    {
                        session.OnFinish(testResult, testCaseContext.Logger);
                    }
                }
            }
            finally
            {
                _testCaseContextFactory.Release(testCaseContext);
            }

            _logger.LogDebug("Finished processing test case [{0}]", testCase.Id);
        }