internal static void StopAllureLogging(TestContext.ResultAdapter testResult, string testUuid, string testContainerUuid, ITest suite, bool updateStopTime, string ignoreReason) { var result = testResult; var testMsg = result.Message; var testStackTrace = result.StackTrace; Logger.LogInProgress( $"Entering stop allure logging for \"{testUuid}\""); if (!string.IsNullOrEmpty(ignoreReason)) { testMsg = ignoreReason; } AllureLifecycle.Instance.UpdateTestCase(testUuid, x => { x.statusDetails.message = MakeGoodErrorMsg(testMsg); x.statusDetails.trace = testStackTrace; x.status = GetNUnitStatus(result.Outcome.Status); }); AllureLifecycle.Instance.StopTestCase(testUuid, updateStopTime); AllureLifecycle.Instance.WriteTestCase(testUuid); AllureLifecycle.Instance.UpdateTestContainer( testContainerUuid, q => q.children.Add(testUuid)); AllureLifecycle.Instance.StopTestContainer( testContainerUuid, updateStopTime); AllureLifecycle.Instance.WriteTestContainer(testContainerUuid); Logger.LogInProgress($"Stopped allure logging for test {testUuid}, {testContainerUuid}, {ignoreReason}"); }
public void AllureOneTimeSetUp() { Logger.LogInProgress( $"Entering OneTimeSetup for \"{TestContext.CurrentContext.Test.Properties.Get(AllureConstants.FixtureUuid)}\""); AllureStorage.MainThreadId = Thread.CurrentThread.ManagedThreadId; _currentSuite = (TestFixture)TestExecutionContext.CurrentContext.CurrentTest; var allTests = ReportHelper.GetAllTestsInSuite(_currentSuite); _currentSuiteTests = allTests; Logger.LogInProgress( $"Exiting OneTimeSetup for \"{_currentSuite.GetProp(AllureConstants.FixtureUuid)}\""); }
internal static void StartTestAndAddPropertiesInside(ITest test, TestFixture suite, int countRun) { var uuid = $"{test.Id}_{Guid.NewGuid():N}"; var testUuid = $"{uuid}-{suite.Id}-test-run{countRun}"; var containerUuid = $"{uuid}-{suite.Id}-run{countRun}-container"; var fixtureUuid = suite.GetPropAsString(AllureConstants.FixtureUuid); test.SetProp(AllureConstants.TestContainerUuid, containerUuid); test.SetProp(AllureConstants.TestUuid, testUuid); test.SetProp(AllureConstants.FixtureUuid, fixtureUuid); test.SetProp(AllureConstants.TestAsserts, new List <Exception>()); ReportHelper.StartAllureLogging(test, testUuid, containerUuid, suite); Logger.LogInProgress( $"Started allure logging for \"{test.FullName}\", run #{countRun}\n\"{testUuid}\"\n\"{containerUuid}\"\n\"{fixtureUuid}\""); suite.GetAllTestsInFixture() .Add((testUuid, containerUuid, fixtureUuid)); suite.GetCountTestInFixture() .Add((testUuid, containerUuid, fixtureUuid)); }
internal static Dictionary <MethodType, string> GetTypeOfCurrentMethodInTest() { var dict = new Dictionary <MethodType, string>(); var methods = GetCallStackMethods().ToList(); if (AllureLifecycle.Instance.Config.Allure.DebugMode) { var sb = new StringBuilder(); methods.ForEach(m => sb.AppendLine(m.Name)); Logger.LogInProgress( $"Test ID {TestExecutionContext.CurrentContext.CurrentTest.Id}, Thread ID {Thread.CurrentThread.ManagedThreadId}, call stack at this moment\n {sb}"); sb.Clear(); } var method = methods.FirstOrDefault(sMethod => { try { _ = sMethod.CustomAttributes; } catch (Exception) { return(false); } var result = sMethod.DeclaringType != typeof(AllureReport); if (!result) { return(false); } var result2 = sMethod.GetCustomAttribute <SetUpAttribute>(); if (result2 != null) { return(true); } var result3 = sMethod.GetCustomAttribute <OneTimeSetUpAttribute>(); if (result3 != null) { return(true); } var result4 = sMethod.GetCustomAttribute <TearDownAttribute>(); if (result4 != null) { return(true); } var result5 = sMethod.GetCustomAttribute <OneTimeTearDownAttribute>(); return(result5 != null); }); if (method == null) { dict.Add(MethodType.TestBody, ""); return(dict); } var methodName = method.Name; var attrs = method.GetCustomAttributes(); var methodType = MethodType.TestBody; foreach (var attribute in attrs) { switch (attribute) { case SetUpAttribute _: methodType = MethodType.Setup; break; case OneTimeSetUpAttribute _: methodType = MethodType.OneTimeSetup; break; case TearDownAttribute _: methodType = MethodType.Teardown; break; case OneTimeTearDownAttribute _: methodType = MethodType.OneTimeTearDown; break; } } dict.Add(methodType, methodName); return(dict); }
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)}\""); }