Search code examples
javaunit-testingjunitassert

Can I write a test without any assert in it?


I'd like to know if it is "ok" to write a test without any "assert" in it. So the test would fail only when an exception / error has occured.

Eg: like a test which has a simple select query, to ensure that the database configuration is right. So when I change some db-configuration, I re-run this test and check if the configuration is right. ?

Thanks!


Solution

  • It is perfectly valid to make sure a unit test runs without encountering an exception.

    As per Matt B's suggestion, be sure to document what the test is actually testing to be clear and precise.