Philzen / rewrite-TestNG-to-JUnit5

An OpenRewrite recipe to migrate your project from TestNG to JUnit 5 (Jupiter)
3 stars 0 forks source link
junit5 openrewrite openrewrite-recipes testng testng-framework

TestNG to Junit5 recipe   Compatible with Java 8

GitHub Actions Workflow StatusSonar Coverage

Converts TestNG test annotations and assertions to Junit 5.

Inspired by the Migrate JUnit 4 @Test annotations to JUnit 5 recipe

Roadmap

This repository is under heavy development. Refer to the project kanban board for ongoing updates on the road to feature completeness. Should you notice a blind spot regarding TestNG features that should be included in a project migration, or if you have idea for a particular implementation, your contributions are welcome!

See below tables for a brief summary of the implementation progress.

Annotations

Annotation on
Class
on
Methods
@Test :heavy_check_mark: :heavy_check_mark:
@Test(description = "%s") :hammer: #23 :heavy_check_mark:
@Test(enabled = false) :hammer: #39 :heavy_check_mark:
@Test(expectedExceptions = Exception.class) :hammer: #20 :heavy_check_mark:
@Test(expectedExceptionsMessageRegExp = "%s") :hammer: #21 :heavy_check_mark:
@Test(groups = "%s") :hammer: #27 :heavy_check_mark:
@Test(timeOut = "%s") :hammer: #25 :heavy_check_mark:
@DataProvider :hammer: #6 :hammer: #38
@Ignore :hammer: #15 :hammer: #15
@Test(enabled = CONSTANT_EXPRESSION) :thinking: #35 :thinking: #35
@Factory :thinking: #8 :thinking: #8
@Test(priority, threadPoolSize) et al. :grey_question: #5 :grey_question: #5

Framework features

Feature on
Class
Tests in inner classes :heavy_check_mark: #30
Assertions :hammer: #3
Lifecycle annotations :hammer: #7
Per class instantiation lifecycle :hammer: #14
SkipException (→ assumption) :hammer: #32
Dependency migration :hammer:#29
Interceptor interfaces :thinking: #10 | #11
Listener interfaces :thinking: #12 | #13

Usage

Prerequisites

Build & install this recipe to your local repository

From the project directory, run one of the following:

Maven

```bash mvn install -DskipTests ```

Gradle

```bash ./gradlew publishToMavenLocal # or ./gradlew pTML # or mvn install ```

This will publish to your local maven repository, typically under ~/.m2/repository.

Migrate a project

Maven

In the `pom.xml` of a different project you wish to run the recipe on, make it a plugin dependency of rewrite-maven-plugin: ```xml org.openrewrite.maven rewrite-maven-plugin 5.33.0 org.philzen.oss.testng.MigrateToJunit5 org.philzen.oss rewrite-testng-to-junit5 1.0.1-SNAPSHOT ``` Now run the recipe via `mvn rewrite:run`.

Gradle

Unlike Maven, Gradle must be explicitly configured to resolve dependencies from Maven local. In the root project of a gradle build that you wish to run this recipe on, make it a dependency of the `rewrite` configuration: ```groovy plugins { id("java") id("org.openrewrite.rewrite") version("latest.release") } repositories { mavenLocal() mavenCentral() } dependencies { rewrite("com.yourorg:rewrite-recipe-starter:latest.integration") } rewrite { activeRecipe("com.yourorg.NoGuavaListsNewArrayList") } ``` Now run the recipe via `gradlew rewriteRun`.