views:

70

answers:

2

I have some common set up code that I've factored out to a method marked with @Before. However, it is not necessary for all this code to run for every single test. Is there a way to mark it so the @Before method only runs before certain tests?

+5  A: 

Just move out the tests that don't need the setup code into a separate test class. If you have some other code common to the tests that would be helpful to keep, move that out into a helper class.

Kirschstein
+1 in other words, don't use @Before if you don't want the behavior of @Before :)
Pascal Thivent
A: 

Or use TestNG. It gives you finer grained control over tests.

duffymo