[Feature request] [Unit test runner] Ability to run test until end, even if Assert fails

Hello,

I have usually more than one assertion in unit tests.

In development and TDD approach, it could be interesting to be able to run a unit test until its end, even if one or more assertion are not met, and to get a message for each failed assertion.

It would help to avoid to have to "run test, encounter one error, fix it, rebuild, run test again, fix next error, etc" if all errors could be summarized on a single run (by "errors" I mean assertions not met, I do not speak about unhandled exceptions of course, for example.

PS : I know a UT must remain short, and not contain a lot of different assertions, but sometimes it's meaningful or useful to assert several things in a single test. My question is not about good practices for unit testing, thank you.

FYI I am using NUnit under VS 2017, all up to date.

Is it possible to plan a such feature for a future release ? (I guess it may also heavily depend of used test unit framework, so maybe it's just not possible from the test runner to enforce this ?).

Regards,

Richard

0
4 comments
Official comment

Hello!

 

Thank you for contacting us.

I've corresponding feature request - https://youtrack.jetbrains.com/issue/RSRP-470822.

Please feel free to comment or vote for it.

Thank you.

Thank you Angelina, I voted it up and I'll keep an eye on it.

Regards

0

@Richard. Two ways around this, I'm assuming you'll prefer the second.

========================

Option A:  Reformat how you write your tests so you have the arrange and act in a SetUp, and the asserts in individual test cases.

[SetUp]
public void ArrangeAndAct()
{
    SUT = MyClass(()
    SUT.MyMethod();
}

[ Test ]
public void result1()
{
    Assert.That( SUT.property1, Is.EqualTo( value );
}

[ Test ]
public void result2()
{
    Assert.That( SUT.property2.  IsEqualTo( value );
}

==================
Option 2

You can use Assert.Multiple

https://github.com/nunit/docs/wiki/Multiple-Assert

This way your test will continue executing even if the first assert fails.  Just make sure you add a meaningful description to your assert.

 

0

Hello Aideneades,

The first solution is obvious for whoever experiencied in unit testing.

The second one is interesting, I wasn't aware of the existence of Assert.Multiple(). I'll test it in R# to see the outcome.

Your link is broken so let me give the right one if it can be useful for anybody else :

https://github.com/nunit/docs/wiki/Multiple-Asserts

I'd prefer a solution integrated in R# unit test runner (as a togglable setting), but meanwhile it's nice to know.

Thanks

0

Please sign in to leave a comment.