Exemple #1
0
        private async Task ExecuteTestCaseAsync(TestCase testCase)
        {
            var correlationId = Correlation.GetTickBasedId();

            using var scope = _logger.BeginScope(correlationId);

            _logger.LogDebug("Starting processing test case [{0}]", testCase.Id);
            var isMuted = testCase.Contains(".muted");

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

            var testResult = new TestCaseExecutionResult(testCase, isMuted);

            _results.Add(testResult);

            using var testCaseContext = CreateContext(testCase, correlationId, Options);
            var descriptionWriter = new XDocumentDescriptionWriter(testCaseContext.Logger);

            try
            {
                _customTestSession?.OnBegin(testCaseContext);
                await testCaseContext.ExecuteActionsAsync(_pipelineActionFactory, testCase.Actions, testCaseContext.Options.GetDeferExceptions(), _logger);
            }
            catch (Exception ex)
            {
                testCaseContext.Logger.LogError(ex, "an error occured");
                testResult.MarkAsFailed(ex);
            }

            try
            {
                testResult.Description = testCaseContext.DescriptionWriter.GetContent();
                _customTestSession?.OnFinish(testResult, testCaseContext.Logger);
            }
            catch (Exception ex)
            {
                testCaseContext.Logger.LogError(ex, "an error occured");
            }

            _logger.LogDebug("Finished processing test case [{0}]", testCase.Id);
        }
Exemple #2
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);
        }