hackjutsu
hackjutsu

Reputation: 8922

@AfterClass method not called when the test suit is terminated manually in Eclipse

I notice that the JUnit's @AfterClass method is not called when the test suit is terminated manually in Eclipse. This causes some trouble in debugging since I'm using the @AfterClass method for cleaning up.

Is there a way to make sure the clean up step is called in this case? (For some reason, I sometimes have to manually stop the tests...)

Thanks:)

Upvotes: 0

Views: 1002

Answers (2)

Shaz
Shaz

Reputation: 1

make sure you have this import import org.testng.annotations.AfterClass; instead of import org.junit.AfterClass;

Upvotes: 0

piotrek
piotrek

Reputation: 14520

First: how does eclipse terminate a running program: https://stackoverflow.com/a/8941751/1100135

So terminating is not specific to JUnit so JUnit can't (or maybe better: shouldn't) do anything about it. So if you reeeeaalyyyy have, you have to program it yourself. You probably don't have many options: shutdown hooks or eclipse plugins. But what if other members of your team will use IntelliJ? or plain maven/gradle/ant?

The real solution is to solve two problems in your tests design. The first is that you have to kill your tests. Fix that! What if you start using CI? The second problem is that your tests have to clean up. Why? What happens if they don't? Try to write them in a way that it doesn't matter.

Upvotes: 1

Related Questions