MBoegers/migrate-testngtojupiter-rewrite

Add Recipe to add @TestInstance(Lifecycle.PER_CLASS) to JUnit Test classes

MBoegers opened this issue · 0 comments

To align JUnit Junipter test behaviors with the TestNGs the annotation @TestInstance(Lifecycle.PER_CLASS) is mandatory.
We need a recipe that adds this annotation to all classes containing Methods annotated with @org.junit.jupiter.api.Test.

Example

Before

import org.junit.jupiter.api.Test;

class MyTest {
  @Test
  void aTest() {}
}

After

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
class MyTest {
  @Test
  void aTest() {}
}

Remark

This recipe should be a general one line the MigrateTestAnnotation one see here