Reputation: 10108
I want to use JUnit to make sure not exception is being thrown during the execution of my program. How can I do that?
Upvotes: 0
Views: 226
Reputation: 612
I'm assuming you're trying to create a wonderful test case, to make sure the specific exception won't get thrown in production mode. A good way is ,in the Sprint Testing and Integration Testing phrases, try to list all potential use cases and ask QA's help. For the cases, use AssertTrue is enough to get all them passed.
Upvotes: -1
Reputation: 9705
If you use JUnit 4, your test method is annotated using @Test
. As long as you do not specify an expected
attribute, any Exception will cause that test to fail. See the JUnit FAQ for details.
Upvotes: 5
Reputation: 3709
JUnit will say that your function did not do as expected (like when an AssertTrue
returns fals, for instance) if it throws an unhandled exception. So, just don't catch it in JUnit and you should be fine.
Upvotes: 4