Migrate to JUnit5 - Part 1#3945
Conversation
| <dependency> | ||
| <groupId>org.junit.jupiter</groupId> | ||
| <artifactId>junit-jupiter</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> |
There was a problem hiding this comment.
This dependency needs to be added to each module (only done yet for pmd-apex and pmd-java). Otherwise IntelliJ won't find the tests.
When building with maven, this is not needed, since the surefire-plugin has these dependency explicit added (junit-jupiter-engine), but eventually, we maybe can remove this extra config for surefire.
| <!-- JUnit5 Platform Engine for Junit 5 --> | ||
| <dependency> | ||
| <groupId>org.junit.jupiter</groupId> | ||
| <artifactId>junit-jupiter-engine</artifactId> | ||
| <version>${junit.version}</version> |
There was a problem hiding this comment.
By adding this here additionally surefire will now find junit3, junit4, junit5 and kotlin tests.
Ideally we can remove this extra config in the end.
Generated by 🚫 Danger |
|
Maybe user |
Update wiremock dependency
- Use static imports for assertions - Use package private tests and classes when possible
adangel
left a comment
There was a problem hiding this comment.
I think, this part 1 is now ready. All tests in pmd-core are migrated.
I'll continue with the other modules in a follow-up PR - this is one is already big...
Maybe user Assertions already in master and use static imports consistently
I didn't change anything on master yet. Not sure, we should do it.Assertionsis junit5 only, which means, we would need to add the junit5 api as a dependency.
However, I changed the style to be consistent (only in pmd-core for now): Now we always use static imports for the assertions/assumptions.
| SystemLambda.restoreSystemProperties(() -> { | ||
| runPmdSuccessfully("--no-cache", "--dir", srcDir, "--rulesets", DUMMY_RULESET, "--report-file", reportFile, "--debug"); | ||
| }); |
There was a problem hiding this comment.
This in an example of how to use SystemLambda, which replaces junit4 system rules
| String log = SystemLambda.tapSystemErrAndOut(() -> { | ||
| runPmd(StatusCode.VIOLATIONS_FOUND, "--no-cache", "--dir", srcDir, "--rulesets", "dummy-basic"); | ||
| }); |
There was a problem hiding this comment.
This is an example to use SystemLambda in order to capture sysout/syserr (we used previously SystemOutRule/SystemErrRule)
| @TempDir | ||
| private Path tempDir; |
There was a problem hiding this comment.
This is a core JUnit5 extension which replaces the TemporaryFolder junit4 rule.
-> https://junit.org/junit5/docs/current/user-guide/#writing-tests-built-in-extensions-TempDirectory
Instead of declaring a field, it can also be used as a test method parameter.
| @ParameterizedTest | ||
| @MethodSource("childrenIndexes") | ||
| void testRemoveChildOfRootNode(final int childIndex) { |
There was a problem hiding this comment.
Example for a parameterized test, which is now a native JUnit5 feature
-> https://junit.org/junit5/docs/current/user-guide/#writing-tests-parameterized-tests
They were merged on separate branches
Describe the PR
Related issues
Ready?
./mvnw clean verifypasses (checked automatically by github actions)