Run Junit @Test that ignores @Before/@After

You can do this with a TestRule. See my answer to Exclude individual test from 'before' method in JUnit. Basically, implement ExternalResource, and in the apply method, check if there is a specific annotation on the method, and if there is, don't run the before/after method. You'll have to specifically call the before/after from your rule though.


If it useless it should not be a problem - does it harm to run the setUp once more?

However I don't think it's possible and looks for me as a cripple feature.

Another approach - move that test to a separate test-class.


With JUnit 5 You can have nested tests using @Nested annotation :

public class MainClass {
 @Nested
  class InnerClass1 {

  @BeforeEach 
  void setup(){}

  @Test 
  void test1(){}
 }

 @Nested
  class InnerClass2 {
  // No setup

  @Test 
  void test2(){}
 }
}