Is there a JUNIT annotation to skip after method for one test method?
annotations, java, junit
Solution
- If you want it to be a bit universal, set a variable "afterToBeLaunched" to false in the @Before. And in the every test that needs @After, set it to true. Of course check it at the start of @After and if it is false, `return` the method.
- If you use JUnit after 4.7 version, use @Rules. ( Apply '@Rule' after each '@Test' and before each '@After' in JUnit ) You can use Rule instead of @After and using TestName, you can read the name of the test there and do finishing actions according to the currently ending test.
Problem
I've 5 test methods in a test class annotated with `@Test`. I've `@Before` and `@After` methods too. Is there a way to skip the method with `@After` only for the first Test method and run it for the rest?