😂 EASY! 🤣
Merlin Bögershausen / @mboegie
TestNG |
➜ | JUnit 🪐 |
😂 EASY! 🤣
Migrate @Before
to JUnit 🪐 API
Migrate Assertions methods
Migrate @Test
Annotation
Grab a drink 🍹🥂🍻🍷☕️
👩🏼💻Manipulate GAV
verify setup with mvn test
🚮 Example Content
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.7.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>compile</scope>
</dependency>
From | To |
---|---|
|
|
|
|
|
|
|
|
src/main/resources/META-INF/rewrite
type: specs.openrewrite.org/v1beta/recipe
name: io.github.mboegers.openrewrite.TestNgToJUnitJupiter
displayName: Migrate Test NG tests to JUnit Jupiter
description: Migrate Test NG annotations and assertions ...
recipeList:
- org.openrewrite.java.ChangeType:
oldFullyQualifiedTypeName: org.testng.annotations.BeforeClass
newFullyQualifiedTypeName: org.junit.jupiter.api.BeforeAll
ignoreDefinition: true
import org.testng.Assert;
class MyTest {
void testMethod() {
boolean actual, expected;
Assert.assertEquals(actual, expected, "😣");
}
}
import org.junit.jupiter.api.Assertions;
class MyTest {
void testMethod() {
boolean actual, expected;
Assertions.assertEquals(expected, actual, "😣");
}
}
@RecipeDescriptor(
name = "Replace `Assert#assertEquals(?, ?)`",
description = "Replace `org.testng.Assert#assertEquals(?, ?)` with `org.junit.jupiter.api.Assertions#assertEquals(?, ?)`."
)
public static class MigrateObjectAssert {
@BeforeTemplate
void before(Object actual, Object expected) {
Assert.assertEquals(actual, expected);
}
@AfterTemplate
void after(Object actual, Object expected) {
Assertions.assertEquals(expected, actual);
}
}
import org.testng.annotations.Test;
class MyTest {
@Test()
void test() {}
}
import org.junit.jupiter.api.Test;
class MyTest {
@Test
void test() {}
}
import org.testng.annotations.Test;
class MyTest {
@Test(enabled = false)
void test() {}
}
If a MethodDeclaration
annotated with o.t.a.Test
and @Test
has not Parameter
then
add @o.j.j.a.Test
add import o.j.j.a.Test
remove o.t.a.Test
with Remove annotation
Join me on helping OpenJDK to migrate from TestNG to JUnit 🪐