Search code examples
javajunitnunit

JUnit equivalent to NUnit Assert.Inconclusive?


I'm a .Net developer and am brand new to Java and JUnit.

I'm used to using the NUnit Assert.Inconclusive() method in certain situations, but I haven't come across the same thing in JUnit.

I poked around the JUnit website as well as a bit on Google and stackoverflow. At a glance, it looks like there's no equivalent in JUnit to the NUnit Assert.Inconclusive() method.

Is that really the case?


Solution

  • I use Inconclusive in NUnit to assert when a precondition for the test is not met.

    For example, if your test requires reading a file then doing something with that input, and maybe the file is missing or the user running the test doesn't have permission to read the file - the test should not fail per-se, because there may be nothing wrong with your algorithm, there is just something wrong with the way the environment in which the test is being run.

    Another use case is if you want to write an integration test that does stuff with a database. If the database is not running or can't be connected to, your test is really inconclusive, not a failure - it never even got off the ground to run due to environment issues.

    For this, I would suggest that @Ignore is not what you want, because that makes your test not run at all. Instead you want to use are the various Assume methods.