1

I'm trying to figure out how to have tests fail as 'Inconclusive' if some required setup that also exists as a test fails.

This is an overly simplified example of what I'm trying to do, but hopefully it illustrates the point:

[Test] public void TestSetter() { Assert.That(() => myInstance.Property = "test", Throws.Nothing); } [Test] public void TestGetter() { try { TestSetter(); } catch (AssertionException) { Assert.Inconclusive("Unable to test, prereq failed"); } Assert.That(myInstance.Property, Is.EqualTo("test")); } 

This doesn't seem to work though, if I force the TestSetter test to fail, both still show the 'Failed' result, instead of the TestGetter resulting in 'Inconclusive'. I stepped through the code, it's definitely hitting the Assert.Inconclusive call, but it seems the earlier AssertionException is still getting precedence.

Is there any way of getting this to correctly report 'Inconclusive'?

Using C#7, with NUnit 3.6.0

2
  • Which version of the NUnit framework are you using? Commented May 22, 2017 at 12:32
  • 1
    @Chris: Version 3.6.0. Commented May 22, 2017 at 12:37

1 Answer 1

1

Try upgrading to NUnit Framework v3.6.1, and see if that runs as you expect.

There was a change in v3.6.0 relating to catching AssertionExceptions, which was later reverted.

See https://github.com/nunit/nunit/issues/2043 for details. To summarise - you should be aware that catching AssertionException's isn't strictly a supported interface to write tests to, and it may be worthwhile refactoring, to test for setup success in a different way.

Sign up to request clarification or add additional context in comments.

2 Comments

Yeah, that fixed it. I'm open to suggestions on how to refactor in this sort of case, but that's delving into the murky world of 'best practices'. Unfortunately in many of my tests, there's another test that sets up the environment I need perfectly and checks it, just running that test is ideal. Until NUnit adds some sort of [Prerequisite(methodname)] feature I can't see a better way of doing it.
Great. There is an open feature request of a Test dependency attribute - you may wish to add your vote. =) github.com/nunit/nunit/issues/51

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.