Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

No report if OneTimeSetUp is failed #1

Closed
undron opened this issue Nov 20, 2017 · 4 comments
Closed

No report if OneTimeSetUp is failed #1

undron opened this issue Nov 20, 2017 · 4 comments

Comments

@undron
Copy link

undron commented Nov 20, 2017

Great job!

But is any ideas, how to bypass error in OneTimeSetUp method for fixture?
This test will not be included in report, because ITestAction attribute will be applied after OneTimeSetUp

    public class Class3
    {
        [OneTimeSetUp]
        public void ThisWillFail()
        {
            var x = 0;
            var y = 1 / x;
        }

        [Test]
        [AllureTest]
        public void Xxx4()
        {
            Assert.True(1 == 2);
        }
    }
@unickq
Copy link
Owner

unickq commented Nov 20, 2017

Hi @undron

Thanks for this case. I'll check whether NUnit allows accessing SetUp methods using ITestAction
nunit/nunit#652

@unickq
Copy link
Owner

unickq commented Nov 20, 2017

@undron
Unfortunatrly ITestAction doesn't allow to use SetUp, TearDown etc

I wrote the following method to bypass it:

public static class AllureHelper {
 public static void SetUp(Action setUpAction) {
  try {
   setUpAction.Invoke();
  } catch (Exception e) {
   var allure = AllureLifecycle.Instance;
   var test = TestContext.CurrentContext.Test;
   var testResult = new TestResult {

    uuid = test.ID,
     name = test.MethodName,
     fullName = test.FullName,
     descriptionHtml = $ "Tests wasn't able to run - an exception occured in setUp methods of <b>{test.ClassName}</b> - {setUpAction.Method.Name} method",
     labels = new List < Label > {
      Label.Suite(test.ClassName),
      Label.Thread(),
      Label.Host(),
      Label.TestClass(test.ClassName),
      Label.TestMethod(test.MethodName),
      Label.Severity(SeverityLevel.blocker)
     }
   };
   allure.StartTestCase(testResult);
   allure.UpdateTestCase(x => x.statusDetails = new StatusDetails {
    message = e.Message,
     trace = e.StackTrace
   });
   allure.StopTestCase(x => x.status = Status.none);
   allure.WriteTestCase(test.ID);
   throw;
  }
}

It's not perfect - but maybe it can help you.

[OneTimeSetUp] //or [SetUp]
public void ThisWillFail()
{
     AllureHelper.SetUp(() =>
     {
          var x = 0;
          var y = 1 / x;
     });            
}

screenshot_1

@undron
Copy link
Author

undron commented Nov 21, 2017

Thank you, I know about nunit/nunit#652 and have no idea too how to bypass it.
Your solutions will work, but anyway you will not see tests, which failed by OneTimeSetup method, but it will be present in TestResult.xml, produced by NUnit:

        <test-suite type="TestFixture" id="0-1011" name="Class3" fullname="NUnit.Allure.Class3" classname="NUnit.Allure.Class3" runstate="Runnable" testcasecount="1" result="Failed" label="Error" site="SetUp" start-time="2017-11-20 13:31:59Z" end-time="2017-11-20 13:31:59Z" duration="0.003892" total="1" passed="0" failed="1" warnings="0" inconclusive="0" skipped="0" asserts="0">
          <failure>
            <message><![CDATA[System.DivideByZeroException : Attempted to divide by zero.]]></message>
            <stack-trace><![CDATA[   at NUnit.Allure.Class3.OneTimeFailedSetup()]]></stack-trace>
          </failure>
          <test-case id="0-1012" name="Xxx4" fullname="NUnit.Allure.Class3.Xxx4" methodname="Xxx4" classname="NUnit.Allure.Class3" runstate="Runnable" seed="1822106949" result="Failed" label="Error" site="Parent" start-time="0001-01-01 00:00:00Z" end-time="0001-01-01 00:00:00Z" duration="0.000000" asserts="0">
            <failure>
              <message><![CDATA[OneTimeSetUp: System.DivideByZeroException : Attempted to divide by zero.]]></message>
            </failure>
          </test-case>
        </test-suite>

@unickq
Copy link
Owner

unickq commented Nov 21, 2017

Yep, unfortunately, I didn't find the solution for current NUnit.
Maybe you would :)
Check https://github.com/nunit/docs/wiki/ICommandWrapper-Interface

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants