Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
137 commits
Select commit Hold shift + click to select a range
15b8c06
Introduce `BugChecker`s TestNG -> JUnit migration
oxkitsune Jun 20, 2022
84e837f
Ignore extends clause in `TestNGClassLevelTestAnnotation`
oxkitsune Aug 31, 2022
2dc2ca8
Handle test setup and teardown migration
oxkitsune Sep 1, 2022
a710edc
Improve `AnnotationAttributeReplacement`
oxkitsune Sep 1, 2022
a70ddc6
Remove redundant naming
oxkitsune Oct 11, 2022
ae9c5ab
Add support for migrating `groups` attribute
oxkitsune Oct 26, 2022
d0a6646
Restructure migration
oxkitsune Jan 19, 2023
8ab052c
Add/remove imports
oxkitsune Jan 19, 2023
aaa8535
Add support for `expectedExceptions` argument
oxkitsune Jan 19, 2023
c50ead9
Tweaks
rickie Jan 20, 2023
cc01fd5
Add XXXs
rickie Jan 20, 2023
18c27a0
Add more test cases
oxkitsune Jan 26, 2023
dc4b1ae
eps suggestions
oxkitsune Jan 26, 2023
acc7d80
suggestions
oxkitsune Jan 26, 2023
87d4cb9
add javadoc
oxkitsune Jan 26, 2023
9c879f2
Remove old code + improve tests
oxkitsune Jan 26, 2023
efd82af
Implement `aggressiveMigration` mode
oxkitsune Jan 26, 2023
05fbfa6
Implement `aggressive` migration mode + tests
oxkitsune Jan 26, 2023
7983bd2
Suggestions and add `XXX`s
rickie Jan 27, 2023
afd10e0
feedback
oxkitsune Feb 2, 2023
d88ff03
Argument migrator
oxkitsune Feb 3, 2023
1565999
begin
oxkitsune Feb 6, 2023
d8ab20d
Refactor `TestNGMetaData` to be immutable
oxkitsune Feb 6, 2023
b922757
Fix tests + behaviour
oxkitsune Feb 13, 2023
06c76de
fmt
oxkitsune Feb 13, 2023
cd119ff
eps suggestions
oxkitsune Feb 13, 2023
e9a1e11
use jspecify `Nullable`
oxkitsune Feb 13, 2023
9976306
add tests for `TestNGScanner`
oxkitsune Feb 13, 2023
9ff0b67
Remove unused `TestNGMigrationContext`
oxkitsune Feb 13, 2023
f30eac9
Create `testngjunitmigrator` module
oxkitsune Feb 13, 2023
d414817
suggestions
oxkitsune Feb 17, 2023
10d2290
Flatten migrator hierarchy
oxkitsune Feb 17, 2023
7a02060
Fix tests
oxkitsune Feb 17, 2023
271362c
Add test case for multiple expected exceptions
oxkitsune Feb 23, 2023
70fc94f
remove old check
oxkitsune Feb 23, 2023
5e50a21
format pom
oxkitsune Feb 23, 2023
5548d25
Initial migration script
oxkitsune Feb 23, 2023
ca5930f
Update run-testng-junit-migration.sh
oxkitsune Feb 23, 2023
df19860
Update README.md
oxkitsune Feb 23, 2023
10549ec
suggestions
oxkitsune Feb 27, 2023
9576719
Improve migration script
oxkitsune Feb 27, 2023
7d76bf0
Improve readme
oxkitsune Feb 27, 2023
ffc9ac2
Assume `@DataProvider` has a return tree
oxkitsune Feb 27, 2023
7a13bd7
Fix build
oxkitsune Feb 27, 2023
aef434b
suggestion
oxkitsune Feb 27, 2023
869736c
Flatten package structure
oxkitsune Feb 27, 2023
278215d
Suggestions and try to make the build green
rickie Feb 27, 2023
6448ea0
Add support for setup/teardown methods
oxkitsune Mar 6, 2023
3d48893
Introduce `EnabledArgumentMigrator`
oxkitsune Mar 13, 2023
d9fadb3
Prevent non-test methods from being flagged as such
oxkitsune Mar 13, 2023
be80044
Return empty fix for enabled test
oxkitsune Mar 13, 2023
4a82876
Handle empty list of `expectedExceptions`
oxkitsune Mar 13, 2023
fe08007
fmt
oxkitsune Mar 13, 2023
0367195
Introduce `GroupsArgumentMigrator`
oxkitsune Mar 13, 2023
65312ba
Adhere to JUnit `Tag` requirements
oxkitsune Mar 13, 2023
c0f69d0
Add tests for `Tag` name specifications
oxkitsune Mar 13, 2023
ca3310b
Copy `SourceCode` from contrib
oxkitsune Mar 13, 2023
cd62517
Copy over `SourceCode` test
oxkitsune Mar 13, 2023
3f4ff35
Make setup/teardown methods static if needed
oxkitsune Mar 13, 2023
ea96c07
Add tests for `TestNGMatchers`
oxkitsune Mar 13, 2023
d3656a1
Suggestions and delete `SourceCodeTest`
rickie Mar 20, 2023
57c29cf
Update and improve `TestNGScanner{,Test}`
rickie Mar 20, 2023
d97de40
Some more tweaks
rickie Mar 20, 2023
9ce14f5
More DataProvider test cases
oxkitsune Mar 20, 2023
e0ea659
eps suggestions
oxkitsune Mar 20, 2023
a63bf8e
Mention picnic specific migration script
oxkitsune Mar 20, 2023
ad8eebc
Improve metadata builder api
oxkitsune Mar 20, 2023
2117337
Tweak README
rickie Mar 23, 2023
8c9a3dd
Further improve README
rickie Mar 23, 2023
1d8c8e7
Improve installion steps
oxkitsune Mar 28, 2023
f32399f
Explain where to run script
oxkitsune Mar 28, 2023
8ff0ba8
Add support for non parent modukes
oxkitsune Mar 28, 2023
4ddf4a7
Add `--count` flag instructions
oxkitsune Mar 28, 2023
548566b
Handle `{Before, After}Test` annotations
oxkitsune Apr 6, 2023
74a3bd7
Version 0.9.1-SNAPSHOT
oxkitsune Apr 6, 2023
8e4ab55
Continue migration if JUnit dependency is present
oxkitsune Apr 6, 2023
08a1d3e
Clarify macos requirements picnic script
oxkitsune Apr 6, 2023
5bb5194
Clarify gnu-{grep, sed} requirements
oxkitsune Apr 6, 2023
714e7d4
Improve macos specific instructions
oxkitsune Apr 6, 2023
11f0aca
Add macOs support to migrator script
oxkitsune Apr 13, 2023
9f3bd61
Use `/bin/bash`
oxkitsune Apr 13, 2023
282ec55
Rename "argument" with "attribute" and minor improvements
rickie Apr 14, 2023
0199fae
Suggestions
rickie Apr 14, 2023
fd87637
`macOs`
oxkitsune Apr 17, 2023
7118931
Add support for the `timeOut` attribute
oxkitsune Apr 17, 2023
1989dd6
Kill mutants in `DataProvider`
oxkitsune Apr 17, 2023
c854189
fmt
oxkitsune Apr 17, 2023
b3ab560
Clarify setup/teardown methods
oxkitsune Apr 17, 2023
2c90517
Specify explicit immutability
oxkitsune Apr 17, 2023
65c26a8
(hopefully) fix SonarCloud warnings
oxkitsune May 8, 2023
7733b7e
0.10.1
oxkitsune May 8, 2023
1628f2e
clean up some code smells
oxkitsune May 8, 2023
dce1a92
Update package-info.java
oxkitsune May 8, 2023
9ee06a3
Replace missed `sed` commands with platform-independent `$sed_command…
DimaLegeza May 9, 2023
0fa2b8d
Emphasize importance of checking migrated code
oxkitsune May 22, 2023
10f474e
Post-rebase fix
rickie May 30, 2023
4fc733d
Post-post rebase fix
rickie May 30, 2023
3635418
Fix pom version
rickie May 30, 2023
c29eaf0
Assorted improvements
rickie May 31, 2023
344ad61
Swap `canFix` and `createFix` and other improvements
rickie Jun 1, 2023
b227470
Use `@Builder` immutable builders
oxkitsune Jun 6, 2023
06f93b8
Add `Known Limitations` section
oxkitsune Jun 6, 2023
dccfbed
Introduce `UnsupportedAttributeMigrator`
oxkitsune Jun 6, 2023
76e6dda
Prefer `attribute` for annotation attributes
oxkitsune Jun 6, 2023
8b9310d
Implement `UnsupportedAttributeMigrator` as `Migrator`
oxkitsune Jun 7, 2023
a1e4d48
Address review
oxkitsune Jun 7, 2023
d354617
Clean up TestNGScanner
oxkitsune Jun 7, 2023
ab0f8c6
fix build
oxkitsune Jun 8, 2023
89bb6fd
Move `VisitorState` to be the last parameter in signature
rickie Jun 8, 2023
be2f6fb
kill mutant
oxkitsune Jun 8, 2023
d38370e
Simplify `AttributeMigrator`
oxkitsune Jun 13, 2023
504e5fe
Add test case for `conservativeMode`
oxkitsune Jun 13, 2023
5d8d078
Kill mutants
oxkitsune Jun 15, 2023
a26af8e
Add `@DataProvider` edge cases
oxkitsune Jun 16, 2023
6d8c1c3
Bump version in `testng-junit-migrator`
rickie May 14, 2024
9b5c6da
Fix Error Prone warnings and pom violation
rickie Jun 19, 2024
532108f
Add specific improvement for OpenJDK
rickie Jun 19, 2024
726194b
Apply EPS suggestions
rickie Jun 19, 2024
8d5a03f
Add Refaster rules
rickie Jun 25, 2024
c978e37
Apply EP best practices suggestions
rickie Jul 1, 2024
b1464f2
Revert "Apply EP best practices suggestions"
rickie Jul 1, 2024
5b17a42
Exclude from analysis
rickie Jul 1, 2024
666794a
Drop incorrect `add-exports`
rickie Jul 2, 2024
27b5058
Introduce Jitpack config
Stephan202 Jul 3, 2024
33214e8
Use compatible Maven
Stephan202 Jul 3, 2024
b5fc0cd
Add spaces when adding `@Test` annotation
rickie Jul 5, 2024
092579d
Some more spaces on other annotations
rickie Jul 5, 2024
556914b
Try to fix the expected exceptions and dataproviders
rickie Jul 14, 2024
09b0804
Initial support for more conservative `expectedExceptions` and datapr…
rickie Jul 15, 2024
88b489f
First part of adding `behaviorPreserving` mode
rickie Jul 15, 2024
78aba43
Add support for minimalChanges flag
rickie Jul 16, 2024
fdf6813
Again some OpenJDK specific fixes
rickie Jul 16, 2024
f33aef9
Try to get the build green
rickie Aug 19, 2025
e058409
Update Maven and JDK versions in Jitpack
rickie Aug 19, 2025
8e7bbb4
Fix Jitpack
Stephan202 Aug 19, 2025
47039b3
Reformat
Stephan202 Aug 19, 2025
ad11590
Resort pom.xml
Stephan202 Aug 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion error-prone-contrib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
9 changes: 9 additions & 0 deletions jitpack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
before_install:
- mvn -version
- source "${HOME}/.sdkman/bin/sdkman-init.sh"
- sdk update
- sdk install java 21.0.7-tem
- sdk use java 21.0.7-tem
- sdk install maven 3.9.11
- sdk use maven 3.9.11
- mvn org.apache.maven.plugins:maven-wrapper-plugin:3.3.2:wrapper -Dmaven=3.9.11
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<module>refaster-runner</module>
<module>refaster-support</module>
<module>refaster-test-support</module>
<module>testng-junit-migrator</module>
</modules>

<scm child.scm.developerConnection.inherit.append.path="false" child.scm.url.inherit.append.path="false">
Expand Down
147 changes: 147 additions & 0 deletions testng-junit-migrator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# TestNG to JUnit Jupiter migrator

This module contains a tool to automatically migrate TestNG tests to JUnit
Jupiter. The tool is built on top of [Error Prone][error-prone-orig-repo]. To
use it, read the installation guide below.

### Installation

1. First, follow Error Prone's [installation
guide][error-prone-installation-guide]. For extra information, see this
[README][eps-readme]. (This step can be skipped for Picnic repositories!)
2. Clone the Error Prone Support repository and checkout the branch
`gdejong/testng-migrator`.
3. Next, run `mvn versions:set -DnewVersion=0.17.1-testng-migration -DgenerateBackupPoms=false`.
This will update set the version to `0.17.1-testng-migration`.
4. Next, run `mvn clean install`. This will create a `0.17.1-testng-migrator` version
of the `testng-junit-migrator` module. The version will now be available in your local Maven repository.
5. Finally, add the following profile to your `pom.xml`. This should be the `pom.xml` in the root of your module.
Usually this is the parent `pom.xml`, but single module projects are also supported.

```xml
<profiles>
<profile>
<id>testng-migrator</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths combine.children="append">
<path>
<groupId>tech.picnic.error-prone-support</groupId>
<artifactId>testng-junit-migrator</artifactId>
<version>0.10.1-testng-migration</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
```

Having this profile allows the migration script to verify the correctness of
the result by making sure the same amount of tests are executed.

## Run the migration

> **Note**
> For Picnic repositories there is an extra step required _before_ running the
> migration, see [here](#picnic-specific).

Now that the migration is set up, one can start the migration by executing the
[run-testng-junit-migrator.sh][migration-script] script in the same directory as the `pom.xml` file we changed earlier.

This script will:

1. Add the required `JUnit` dependencies to your `pom.xml`.
2. Run the `testng-to-junit` migration.

> **Note**
> Please verify that the migrated code still compiles after each step of the compilation.

### Counting tests

The amount of tests executed before the migration can be counted using the `--count` flag:
```sh
./run-testng-junit-migrator.sh --count
```
This will count the amount of tests that are executed. This is recommended before running the migration
to allow for comparison.

### Picnic specific

The `PicnicSupermarket/picnic-scratch` repository contains a helper script
`java-platform/testng-junit-migration.sh` that migrates some more
Picnic-specific code. This should be executed _before_ starting the actual
migration.

> **Warning**
> This is a warning for `macOs` users.
> Make sure gnu-grep and gnu-sed are installed!
>
> ```brew install grep gnu-sed```

Continue with performing the actual migration [here](#run-the-migration).
Afterward, run the `./picnic-shared-tools/patch.sh` script.

Now you are done! 🤘🚀

### Migration code example

Consider the following TestNG test class:

```java
// TestNG code:
@Test
public class A {
public void simpleTest() {}

@Test(priority = 2)
public void priorityTest() {}

@DataProvider
private static Object[][] dataProviderTestCases() {
return new Object[]{{1}, {2}, {3}};
}

@Test(dataProvider = "dataProviderTestCases")
public void dataProviderTest(int number) {}
}
```

This migration tool will turn this into the following:

```java
// JUnit Jupiter code:
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class A {
@Test
void simpleTest() {}

@Test
@Order(2)
public void priorityTest() {}

private static Stream<Argument> dataProviderTestCases() {
return Stream.of(arguments(1), arguments(2), arguments(3));
}

@ParameterizedTest
@MethodSource("dataProviderTestCases")
public void dataProviderTest(int number) {}
}
```

### Known limitations
- Certain `@DataProvider` methods cannot be automatically migrated (e.g., `return Stream.of(...).toArray(Object[][]::new)`).
- Some uncommon `@Test` attributes are not supported, such as `ignoreMissingDependencies` and `dependsOnMethods`.
- Test setup and teardown methods `@{Before, After}Test` are migrated to `@{Before, After}Each` to avoid introducing breaking changes. `@{Before, After}All` require a static method, while `@{Before, After}Test` are instance methods.

[eps-readme]: ../README.md
[error-prone-installation-guide]: https://errorprone.info/docs/installation#maven
[error-prone-orig-repo]: https://github.com/google/error-prone
[migration-script]: run-testng-junit-migration.sh
161 changes: 161 additions & 0 deletions testng-junit-migrator/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>tech.picnic.error-prone-support</groupId>
<artifactId>error-prone-support</artifactId>
<version>0.24.1-SNAPSHOT</version>
</parent>

<artifactId>testng-junit-migrator</artifactId>

<name>Picnic :: Error Prone Support :: TestNG JUnit Migrator</name>
<description>A tool to migrate TestNG tests to JUnit</description>
<url>https://error-prone.picnic.tech</url>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>refaster-compiler</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>refaster-support</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>refaster-test-support</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.auto</groupId>
<artifactId>auto-common</artifactId>
</dependency>
<dependency>
<groupId>com.google.auto.service</groupId>
<artifactId>auto-service-annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.auto.value</groupId>
<artifactId>auto-value-annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_annotation</artifactId>
</dependency>
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_check_api</artifactId>
</dependency>
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_test_helpers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jspecify</groupId>
<artifactId>jspecify</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-java</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-java-11</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-templating</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.openrewrite</groupId>
<artifactId>rewrite-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths combine.children="append">
<path>
<groupId>${project.groupId}</groupId>
<artifactId>refaster-compiler</artifactId>
<version>${project.version}</version>
</path>
<path>
<groupId>${project.groupId}</groupId>
<artifactId>refaster-support</artifactId>
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
<compilerArgs combine.children="append">
<arg>-Xplugin:RefasterRuleCompiler</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Loading
Loading