Example #1
0
        public void AllureOneTimeTearDown()
        {
            Logger.LogInProgress(
                $"Entering OneTimeTearDown for \"{_currentSuite.GetProp(AllureConstants.FixtureUuid)}\"");

            if (_currentSuite.GetCurrentOneTimeTearDownFixture() != null)
            {
                string testMsg        = null;
                string testStackTrace = null;
                var    status         = ReportHelper.GetNUnitStatus(TestContext.CurrentContext.Result.Outcome.Status);

                if (TestContext.CurrentContext.Result.Outcome.Site == FailureSite.TearDown)
                {
                    testStackTrace = TestContext.CurrentContext.Result.StackTrace;
                    testMsg        = TestContext.CurrentContext.Result.Message;
                }

                AllureLifecycle.Instance.StopFixture(
                    _currentSuite.GetCurrentOneTimeTearDownFixture().suiteUuid + "-onetimeteardown",
                    q =>
                {
                    q.status = status;
                    q.statusDetails.message = testMsg;
                    q.statusDetails.trace   = testStackTrace;
                });
                TestExecutionContext.CurrentContext.CurrentTest.SetCurrentOneTimeTearDownFixture(new FixtureResult
                {
                    suiteUuid = "null"
                });
            }

            foreach (var testTupleInfo in TestExecutionContext.CurrentContext.CurrentTest.GetCompletedTestsInFixture())
            {
                AllureLifecycle.Instance.Storage.ClearStepContext();
                AllureLifecycle.Instance.Storage.CurrentThreadStepContext.AddLast(testTupleInfo.TestUuid);
                ReportHelper.StopAllureLogging(testTupleInfo.testResult,
                                               testTupleInfo.TestUuid, testTupleInfo.TestContainerUuid, _currentSuite, false, null);
            }

            if (string.IsNullOrEmpty(TestContext.CurrentContext.Test.MethodName) &&
                TestContext.CurrentContext.Result.Outcome.Site == FailureSite.SetUp &&
                AllureLifecycle.Instance.Config.Allure.AllowEmptySuites &&
                TestContext.CurrentContext.Result.Outcome.Status == TestStatus.Failed)
            {
                lock (ReportHelper.Locker)
                {
                    AllureStorage.MainThreadId = Thread.CurrentThread.ManagedThreadId;
                    foreach (var test in _currentSuiteTests)
                    {
                        test.Properties.Set(AllureConstants.TestResult, TestContext.CurrentContext.Result);
                        AllureLifecycle.Instance.UpdateTestContainer(
                            test.Properties.Get(AllureConstants.TestContainerUuid)
                            .ToString(),
                            x => x.start = AllureLifecycle.ToUnixTimestamp());
                        AllureLifecycle.Instance.UpdateTestCase(test.Properties
                                                                .Get(AllureConstants.TestUuid).ToString(),
                                                                x => { x.start = AllureLifecycle.ToUnixTimestamp(); });
                        Thread.Sleep(5);
                        AllureLifecycle.Instance.Storage.ClearStepContext();
                        AllureLifecycle.Instance.Storage.CurrentThreadStepContext.AddLast(test.Properties
                                                                                          .Get(AllureConstants.TestUuid).ToString());
                        AllureLifecycle.Instance.StartStepAndStopIt(null, "The test was not started",
                                                                    Status.failed);
                        AllureLifecycle.Instance.UpdateTestCase(
                            test.Properties.Get(AllureConstants.TestUuid).ToString(),
                            x =>
                        {
                            x.labels.RemoveAll(q => q.name == "thread");
                            x.labels.Add(Label.Thread());
                        });
                        ReportHelper.StopAllureLogging(TestContext.CurrentContext.Result, test.Properties
                                                       .Get(AllureConstants.TestUuid).ToString(), test.Properties
                                                       .Get(AllureConstants.TestContainerUuid).ToString(), _currentSuite, true, null);
                    }
                }
            }

            else
            {
                ReportHelper.AddIgnoredTestsToReport(_currentSuite);
            }

            lock (ReportHelper.Locker)
            {
                EnvironmentBuilder.BuildEnvFile(new DirectoryInfo(AllureLifecycle.Instance.ResultsDirectory));
            }

            Logger.LogInProgress(
                $"Exiting OneTimeTearDown for \"{TestContext.CurrentContext.Test.Properties.Get(AllureConstants.FixtureUuid)}\"");
        }