I understand it gets called after each test method but can somebody explicitly tell me whether it gets called if the test methods throws an exception?
Yes, it is called after each testXXX method.
When is the tearDown() method called in JUnit? Explanation: The tearDown() method is called after the execution of every @Test method. 8.
tearDown()Provides an opportunity to perform cleanup after each test method in a test case ends.
JUnit creates all the TestCase instances up front, and then for each instance, calls setup(), the test method, and tearDown(). In other words, the subtle difference is that constructors are all invoked in batch up front, whereas the setUp() method is called right before each test method.
Read the docs:
All
@After
methods are guaranteed to run even if aBefore
orTest
method throws an exception.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With