junit5 icon indicating copy to clipboard operation
junit5 copied to clipboard

Add `org.junit.openrewrite.SanityCheck`

Open Pankraz76 opened this issue 3 months ago • 4 comments

Add org.junit.openrewrite.SanityCheck

enabler for:

  • https://docs.openrewrite.org/recipes/java/testing/junit/jupiterbestpractices
  • https://docs.openrewrite.org/recipes/staticanalysis/commonstaticanalysis
  • https://docs.openrewrite.org/recipes/java/migrate/upgradetojava17

related to:

  • https://github.com/junit-team/junit-framework/pull/5191
  • https://github.com/diffplug/spotless/pull/2651
  • https://github.com/diffplug/spotless/pull/2636

I hereby agree to the terms of the JUnit Contributor License Agreement.


Definition of Done

Pankraz76 avatar Dec 02 '25 10:12 Pankraz76

discovering the specialties took more than 2h to collect.

Of course junit worth every effort.

BUILD SUCCESSFUL in 3m 19s

making this fully reprod. is first premise:

image

Pankraz76 avatar Dec 03 '25 19:12 Pankraz76

should have done more early related topics into one PR with dedicated commits... sorry for this inconvenience.

Pankraz76 avatar Dec 04 '25 12:12 Pankraz76

✅ All tests passed ✅

🏷️ Commit: 4c1138f4493b2a1221f1fa29e35c16d29fdc292d ▶️ Tests: 53948 executed ⚪️ Checks: 18/18 completed


Learn more about TestLens at testlens.app.

testlens-app[bot] avatar Dec 05 '25 11:12 testlens-app[bot]

Kindly asking, if this is any good? @sbrannen @marcphilipp

Assuming the junit rules could help to embrace some junit conventions and best practices.

Thanks to the community.

Pankraz76 avatar Dec 10 '25 12:12 Pankraz76

As indicated in https://github.com/junit-team/junit-framework/pull/4708#issuecomment-3056745890, we don't want to add another static analysis tool to our build because of the additional execution time (even if it's "just" on GitHub Actions) and maintenance burden in our build.

Regarding the code changes made by the two rules you added to the SanityCheck configuration, we don't think EqualsAvoidsNull is useful for us since we've adopted JSpecify and NullAway and TimeRules seems to have made a single change in test code.

marcphilipp avatar Dec 13 '25 10:12 marcphilipp

yes of course. Its actually ment to be used as into. The dedicated junit rules make a lot of changes, meaning junit it not quite aligned with its own best practises and conventions.

Is this something to consider?

The diff there is quite easy to see whats the benefit is provided.

Pankraz76 avatar Dec 13 '25 10:12 Pankraz76

I'm not really surprised by this. Our tests have to cover edge cases outside of the best practices. Moreover, testing JUnit with JUnit comes with its own set of challenges, so we can't always follow "best practices". For example, when testing assertions, we don't want to relay on assertions but use try-catch blocks.

marcphilipp avatar Dec 13 '25 11:12 marcphilipp

this the classic one i´ve been doing wrong for 15 years, so seems junit too, which is nothing to be worried about its something everybody having issues with, everyone except computer:

  • org.openrewrite.java.testing.cleanup.AssertionsArgumentOrder
> Task :platform-tests:rewriteRun
Changes have been made to platform-tests/src/test/java/org/junit/platform/reporting/legacy/xml/LegacyXmlReportGeneratingListenerTests.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.cleanup.RemoveTestPrefix
Changes have been made to platform-tests/src/test/java/org/junit/platform/reporting/open/xml/OpenTestReportGeneratingListenerTests.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.cleanup.TestsShouldNotBePublic
Changes have been made to platform-tests/src/test/java/org/junit/platform/reporting/open/xml/JUnitContributorTests.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.cleanup.TestsShouldNotBePublic
Changes have been made to platform-tests/src/test/java/org/junit/platform/launcher/core/DefaultLauncherTests.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.junit5.AssertThrowsOnLastStatement
Changes have been made to platform-tests/src/test/java/org/junit/platform/launcher/core/LauncherFactoryTests.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.cleanup.RemoveTestPrefix
Changes have been made to platform-tests/src/test/java/org/junit/platform/launcher/core/StreamInterceptorTests.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.cleanup.SimplifyTestThrows
Changes have been made to platform-tests/src/test/java/org/junit/platform/launcher/core/HierarchicalOutputDirectoryCreatorTests.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.cleanup.TestsShouldNotBePublic
Changes have been made to platform-tests/src/test/java/org/junit/platform/launcher/core/ExecutionListenerAdapterTests.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.cleanup.RemoveTestPrefix
Changes have been made to platform-tests/src/test/java/org/junit/platform/launcher/core/ListenerRegistryTests.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.cleanup.TestsShouldNotBePublic
Changes have been made to platform-tests/src/test/java/org/junit/platform/launcher/core/InternalTestPlanTests.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.cleanup.TestsShouldNotBePublic
Changes have been made to platform-tests/src/test/java/org/junit/platform/launcher/listeners/SummaryGenerationTests.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.cleanup.TestsShouldNotBePublic
Changes have been made to platform-tests/src/test/java/org/junit/platform/launcher/listeners/discovery/LoggingLauncherDiscoveryListenerTests.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.cleanup.TestsShouldNotBePublic
Changes have been made to platform-tests/src/test/java/org/junit/platform/launcher/listeners/LoggingListenerTests.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.cleanup.TestsShouldNotBePublic
Changes have been made to platform-tests/src/test/java/org/junit/platform/launcher/listeners/session/CompositeLauncherSessionListenerTests.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.cleanup.TestsShouldNotBePublic
Changes have been made to platform-tests/src/test/java/org/junit/platform/commons/util/ReflectionUtilsWithGenericTypeHierarchiesTests.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.cleanup.TestsShouldNotBePublic
Changes have been made to platform-tests/src/test/java/org/junit/platform/commons/util/DefaultClasspathScannerTests.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.cleanup.SimplifyTestThrows
Changes have been made to platform-tests/src/test/java/org/junit/platform/commons/annotation/TestableAnnotationTests.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.cleanup.RemoveTestPrefix
Changes have been made to platform-tests/src/test/java/org/junit/platform/commons/function/TryTests.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.cleanup.TestsShouldNotBePublic
Changes have been made to platform-tests/src/test/java/org/junit/platform/commons/support/ResourceInteroperabilityTests.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.cleanup.TestsShouldNotBePublic
Changes have been made to platform-tests/src/test/java/org/junit/platform/engine/DiscoveryIssueTests.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.cleanup.TestsShouldNotBePublic
Changes have been made to platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/ForkJoinDeadLockTests.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.cleanup.TestsShouldNotBePublic
Changes have been made to platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/SameThreadExecutionIntegrationTests.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.cleanup.SimplifyTestThrows
Changes have been made to platform-tests/src/test/java/org/junit/platform/engine/support/discovery/EngineDiscoveryRequestResolverTests.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.cleanup.TestsShouldNotBePublic
Changes have been made to platform-tests/src/test/java/org/junit/platform/engine/support/descriptor/ClassSourceTests.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.cleanup.SimplifyTestThrows
Changes have been made to platform-tests/src/test/java/org/junit/platform/engine/support/store/NamespaceTests.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.cleanup.TestsShouldNotBePublic
Changes have been made to platform-tests/src/test/java/org/junit/platform/engine/TestTagTests.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.junit5.CleanupAssertions
            org.openrewrite.java.testing.cleanup.AssertionsArgumentOrder
Changes have been made to platform-tests/src/test/java/org/junit/platform/StackTracePruningTests.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.junit5.StaticImports
            org.openrewrite.java.UseStaticImport: {methodPattern=org.junit.jupiter.api.Assertions *(..)}
Changes have been made to platform-tests/src/test/java/org/junit/platform/console/output/TestFeedPrintingListenerTests.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.cleanup.RemoveTestPrefix
        org.openrewrite.java.testing.cleanup.TestsShouldNotBePublic
Changes have been made to platform-tests/src/test/java/org/junit/platform/console/ConsoleLauncherIntegrationTests.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.cleanup.SimplifyTestThrows
Changes have been made to platform-tests/src/jmh/java/org/junit/jupiter/jmh/AssertionBenchmarks.java by:
    org.openrewrite.java.testing.junit.JupiterBestPractices
        org.openrewrite.java.testing.junit5.StaticImports
            org.openrewrite.java.UseStaticImport: {methodPattern=org.junit.jupiter.api.Assertions *(..)}
        org.openrewrite.java.testing.cleanup.AssertLiteralBooleanRemovedRecipe
Please review and commit the results.
Estimate time saved: 1h 50m

Pankraz76 avatar Dec 13 '25 16:12 Pankraz76