Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does tearDown get called if test case throws exception? (JUnit) [closed]

Tags:

junit

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?

like image 527
dln Avatar asked Feb 28 '12 22:02

dln


People also ask

Does tearDown run after each test?

Yes, it is called after each testXXX method.

What is the tearDown method called in JUnit?

When is the tearDown() method called in JUnit? Explanation: The tearDown() method is called after the execution of every @Test method. 8.

What does the tearDown () function do?

tearDown()Provides an opportunity to perform cleanup after each test method in a test case ends.

What is setUp and tearDown in JUnit?

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.


1 Answers

Read the docs:

All @After methods are guaranteed to run even if a Before or Test method throws an exception.

like image 63
The Nail Avatar answered Sep 28 '22 22:09

The Nail