diff --git a/documentation/documentation.gradle b/documentation/documentation.gradle index d1b6b671c4c8..9ce6bd12e685 100644 --- a/documentation/documentation.gradle +++ b/documentation/documentation.gradle @@ -57,7 +57,7 @@ configurations { javadocClasspath { description = 'Class files for the javadoc to be built' - resolutionStrategy.capabilitiesResolution.withCapability('org.junit.jupiter:junit-jupiter-params:'+testLibs.versions.junit5.get()) { details -> + resolutionStrategy.capabilitiesResolution.withCapability('org.junit.jupiter:junit-jupiter-params:'+testLibs.versions.junitJupiter.get()) { details -> details.select( details.candidates.first() ).because( 'first' ) } diff --git a/hibernate-testing/README.adoc b/hibernate-testing/README.adoc index f31ca76d5bd1..1ec8b0d3fa30 100644 --- a/hibernate-testing/README.adoc +++ b/hibernate-testing/README.adoc @@ -1,7 +1,7 @@ The `hibernate-testing` module of Hibernate ORM defines utilities for writing tests easier. -This documentation focuses on the JUnit 5 & annotation based testing support... +This documentation focuses on the JUnit 6 & annotation based testing support... -// todo (6.1) : write more (duh) \ No newline at end of file +// todo (6.1) : write more (duh) diff --git a/hibernate-testing/hibernate-testing.gradle b/hibernate-testing/hibernate-testing.gradle index c80d85417513..f71cfe797481 100644 --- a/hibernate-testing/hibernate-testing.gradle +++ b/hibernate-testing/hibernate-testing.gradle @@ -15,8 +15,8 @@ dependencies { api project( ':hibernate-community-dialects' ) api testLibs.junit4 - api testLibs.junit5Api - api testLibs.junit5Params + api testLibs.junitJupiterApi + api testLibs.junitJupiterParams api testLibs.hamcrest api testLibs.assertjCore @@ -55,8 +55,8 @@ dependencies { // Since we don't need WildFly Elytron in our tests, we'll just exclude it. exclude group: 'org.wildfly.security', module: 'wildfly-elytron' } - implementation testLibs.junit5Engine - implementation testLibs.junit5Launcher + implementation testLibs.junitJupiterEngine + implementation testLibs.junitJupiterLauncher annotationProcessor project( ':hibernate-processor' ) } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/AfterClassOnce.java b/hibernate-testing/src/main/java/org/hibernate/testing/AfterClassOnce.java index 861fac3f5ed7..0efaaa58bc02 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/AfterClassOnce.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/AfterClassOnce.java @@ -15,7 +15,7 @@ * except this annotation need not be attached to a static method * * @author Steve Ebersole - * @deprecated Use JUnit 5 along with one of the Hibernate ORM's class-level test annotations + * @deprecated Use JUnit Jupiter along with one of the Hibernate ORM's class-level test annotations * ({@link org.hibernate.testing.orm.junit.BaseUnitTest}, * {@link org.hibernate.testing.orm.junit.SessionFactory}, * {@link org.hibernate.testing.orm.junit.Jpa}, diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/BeforeClassOnce.java b/hibernate-testing/src/main/java/org/hibernate/testing/BeforeClassOnce.java index aea5b0c2f5b6..cd062107cc46 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/BeforeClassOnce.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/BeforeClassOnce.java @@ -15,7 +15,7 @@ * except this annotation need not be attached to a static method * * @author Steve Ebersole - * @deprecated Use JUnit 5 along with one of the Hibernate ORM's class-level test annotations + * @deprecated Use JUnit Jupiter along with one of the Hibernate ORM's class-level test annotations * ({@link org.hibernate.testing.orm.junit.BaseUnitTest}, * {@link org.hibernate.testing.orm.junit.SessionFactory}, * {@link org.hibernate.testing.orm.junit.Jpa}, diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/FailureExpected.java b/hibernate-testing/src/main/java/org/hibernate/testing/FailureExpected.java index f45c2ac1d91b..64fcb5c31c86 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/FailureExpected.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/FailureExpected.java @@ -14,7 +14,7 @@ * * @author Hardy Ferentschik * @author Steve Ebersole - * @deprecated Use JUnit 5 and {@link org.hibernate.testing.orm.junit.FailureExpected} instead. + * @deprecated Use JUnit Jupiter and {@link org.hibernate.testing.orm.junit.FailureExpected} instead. */ @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.METHOD, ElementType.TYPE }) diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/OnExpectedFailure.java b/hibernate-testing/src/main/java/org/hibernate/testing/OnExpectedFailure.java index 18e6966c82e4..36c4b6791f03 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/OnExpectedFailure.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/OnExpectedFailure.java @@ -13,7 +13,7 @@ * Annotation used to identify a method as a callback to be executed whenever a {@link FailureExpected} is handled. * * @author Steve Ebersole - * @deprecated No replacement with JUnit 5 at the moment. + * @deprecated No replacement with JUnit Jupiter at the moment. */ @Retention( RetentionPolicy.RUNTIME ) @Target( ElementType.METHOD ) diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/OnFailure.java b/hibernate-testing/src/main/java/org/hibernate/testing/OnFailure.java index d87f327c3fc2..8de16933ef8e 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/OnFailure.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/OnFailure.java @@ -13,7 +13,7 @@ * Annotation used to identify a method as a callback to be executed on test failures. * * @author Steve Ebersole - * @deprecated No replacement with JUnit 5 at the moment. + * @deprecated No replacement with JUnit Jupiter at the moment. */ @Retention( RetentionPolicy.RUNTIME ) @Target( ElementType.METHOD ) diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/RequiresDialect.java b/hibernate-testing/src/main/java/org/hibernate/testing/RequiresDialect.java index 8d8a621acf98..6ac280c7d7e8 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/RequiresDialect.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/RequiresDialect.java @@ -19,7 +19,7 @@ * @see RequiresDialects * * @author Hardy Ferentschik - * @deprecated Use JUnit 5 and {@link org.hibernate.testing.orm.junit.RequiresDialect} instead. + * @deprecated Use JUnit Jupiter and {@link org.hibernate.testing.orm.junit.RequiresDialect} instead. */ @Target({ ElementType.METHOD, ElementType.TYPE }) @Retention(RetentionPolicy.RUNTIME) diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/RequiresDialectFeature.java b/hibernate-testing/src/main/java/org/hibernate/testing/RequiresDialectFeature.java index 54637b6d7ae5..2638cfb44a81 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/RequiresDialectFeature.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/RequiresDialectFeature.java @@ -14,7 +14,7 @@ * specified feature. * * @author Hardy Ferentschik - * @deprecated Use JUnit 5 and {@link org.hibernate.testing.orm.junit.RequiresDialectFeature} instead. + * @deprecated Use JUnit Jupiter and {@link org.hibernate.testing.orm.junit.RequiresDialectFeature} instead. */ @Target({ ElementType.METHOD, ElementType.TYPE }) @Retention(RetentionPolicy.RUNTIME) diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/RequiresDialects.java b/hibernate-testing/src/main/java/org/hibernate/testing/RequiresDialects.java index 37139c4fa569..2ba1ecff385a 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/RequiresDialects.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/RequiresDialects.java @@ -14,7 +14,7 @@ * Useful when test needs to be run against more than one dialect because of a different reason. * * @author Lukasz Antoniak - * @deprecated Use JUnit 5 and {@link org.hibernate.testing.orm.junit.RequiresDialects} instead. + * @deprecated Use JUnit Jupiter and {@link org.hibernate.testing.orm.junit.RequiresDialects} instead. */ @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.METHOD, ElementType.TYPE }) diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/Skip.java b/hibernate-testing/src/main/java/org/hibernate/testing/Skip.java index 595f6b83713f..6dc7dea07d90 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/Skip.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/Skip.java @@ -13,7 +13,7 @@ * An annotation, used in combination with {@link Matcher}, to determine when/if tests should be skipped. * * @author Steve Ebersole - * @deprecated Use JUnit 5 and {@link org.junit.jupiter.api.condition.DisabledOnOs} + * @deprecated Use JUnit Jupiter and {@link org.junit.jupiter.api.condition.DisabledOnOs} * or {@link org.junit.jupiter.api.condition.DisabledIf}. */ @Retention( RetentionPolicy.RUNTIME ) diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/SkipForDialect.java b/hibernate-testing/src/main/java/org/hibernate/testing/SkipForDialect.java index de5c8fb3926a..6c41aa793c17 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/SkipForDialect.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/SkipForDialect.java @@ -20,7 +20,7 @@ * * @author Hardy Ferentschik * @author Steve Ebersole - * @deprecated Use JUnit 5 and {@link org.hibernate.testing.orm.junit.SkipForDialect} instead. + * @deprecated Use JUnit Jupiter and {@link org.hibernate.testing.orm.junit.SkipForDialect} instead. */ @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.METHOD, ElementType.TYPE }) diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/SkipForDialects.java b/hibernate-testing/src/main/java/org/hibernate/testing/SkipForDialects.java index 5c4df318cefc..42cb721a70c6 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/SkipForDialects.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/SkipForDialects.java @@ -14,7 +14,7 @@ * Useful when more than one dialect needs to be skipped because of a different reason. * * @author Lukasz Antoniak - * @deprecated Use JUnit 5 and {@link org.hibernate.testing.orm.junit.SkipForDialectGroup} instead. + * @deprecated Use JUnit Jupiter and {@link org.hibernate.testing.orm.junit.SkipForDialectGroup} instead. */ @Retention(RetentionPolicy.RUNTIME) @Target({ ElementType.METHOD, ElementType.TYPE }) diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/bytecode/enhancement/extension/BytecodeEnhancementPostDiscoveryFilter.java b/hibernate-testing/src/main/java/org/hibernate/testing/bytecode/enhancement/extension/BytecodeEnhancementPostDiscoveryFilter.java index a6fb9f7b43db..197ee5ccda41 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/bytecode/enhancement/extension/BytecodeEnhancementPostDiscoveryFilter.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/bytecode/enhancement/extension/BytecodeEnhancementPostDiscoveryFilter.java @@ -8,6 +8,7 @@ import static org.junit.platform.commons.util.AnnotationUtils.isAnnotated; import org.hibernate.testing.bytecode.enhancement.extension.engine.BytecodeEnhancedEngineDescriptor; +import org.hibernate.testing.bytecode.enhancement.extension.engine.BytecodeEnhancedTestEngine; import org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor; import org.junit.platform.engine.FilterResult; import org.junit.platform.engine.TestDescriptor; @@ -24,6 +25,11 @@ public FilterResult apply(TestDescriptor testDescriptor) { } boolean isEnhanced = isAnnotated( descriptor.getTestClass(), BytecodeEnhanced.class ); + if ( isEnhanced && !BytecodeEnhancedTestEngine.isEnabled() ) { + throw new IllegalStateException( + "BytecodeEnhancedTestEngine is disabled. But the tests rely on the @BytecodeEnhanced extensions: %s. In order to run this test, make sure to exactly align your dependency to JUnit with that of hibernate-testing, and set system property '%s=true'.".formatted( + descriptor, BytecodeEnhancedTestEngine.ENHANCEMENT_EXTENSION_ENGINE_ENABLED ) ); + } if ( root instanceof BytecodeEnhancedEngineDescriptor ) { if ( !isEnhanced ) { return FilterResult.excluded( "Not bytecode enhanced." ); @@ -32,7 +38,7 @@ public FilterResult apply(TestDescriptor testDescriptor) { else { if ( isEnhanced ) { testDescriptor.removeFromHierarchy(); - return FilterResult.excluded( "Not bytecode enhanced." ); + return FilterResult.excluded( "Not bytecode enhanced engine, but test requires bytecode enhancement." ); } } } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/bytecode/enhancement/extension/engine/BytecodeEnhancedTestEngine.java b/hibernate-testing/src/main/java/org/hibernate/testing/bytecode/enhancement/extension/engine/BytecodeEnhancedTestEngine.java index 3bccc2927867..6caaf1395c0a 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/bytecode/enhancement/extension/engine/BytecodeEnhancedTestEngine.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/bytecode/enhancement/extension/engine/BytecodeEnhancedTestEngine.java @@ -31,6 +31,7 @@ import org.junit.jupiter.api.TestInstance; import org.junit.jupiter.api.extension.ExecutionCondition; import org.junit.jupiter.api.extension.Extension; +import org.junit.jupiter.api.extension.ExtensionConfigurationException; import org.junit.jupiter.api.extension.ExtensionContext; import org.junit.jupiter.api.extension.TestInstantiationAwareExtension; import org.junit.jupiter.api.io.CleanupMode; @@ -41,22 +42,29 @@ import org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor; import org.junit.jupiter.engine.descriptor.ClassTestDescriptor; import org.junit.jupiter.engine.descriptor.JupiterEngineDescriptor; -import org.junit.jupiter.engine.descriptor.LauncherStoreFacade; import org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor; import org.junit.jupiter.engine.descriptor.TestTemplateTestDescriptor; import org.junit.jupiter.engine.execution.JupiterEngineExecutionContext; +import org.junit.jupiter.engine.execution.LauncherStoreFacade; import org.junit.platform.engine.EngineDiscoveryRequest; import org.junit.platform.engine.EngineExecutionListener; import org.junit.platform.engine.ExecutionRequest; +import org.junit.platform.engine.OutputDirectoryCreator; import org.junit.platform.engine.TestDescriptor; import org.junit.platform.engine.UniqueId; -import org.junit.platform.engine.reporting.OutputDirectoryProvider; +import org.junit.platform.engine.support.descriptor.EngineDescriptor; import org.junit.platform.engine.support.hierarchical.EngineExecutionContext; import org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine; import org.junit.platform.engine.support.hierarchical.ThrowableCollector; public class BytecodeEnhancedTestEngine extends HierarchicalTestEngine { + public static final String ENHANCEMENT_EXTENSION_ENGINE_ENABLED = "hibernate.testing.bytecode.enhancement.extension.engine.enabled"; + + public static boolean isEnabled() { + return "true".equalsIgnoreCase( System.getProperty( ENHANCEMENT_EXTENSION_ENGINE_ENABLED, "false" ) ); + } + @Override public String getId() { return "bytecode-enhanced-engine"; @@ -64,6 +72,24 @@ public String getId() { @Override public TestDescriptor discover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) { + if ( isEnabled() ) { + try { + return doDiscover( discoveryRequest, uniqueId ); + } + catch (OutOfMemoryError e) { + throw e; + } + catch (Error e) { + throw new ExtensionConfigurationException( + "Encountered a problem when enhancing the test classes. It is highly likely that @BytecodeEnhanced extension is incompatible with the provided version of JUnit.", + e ); + } + } + + return new EngineDescriptor( uniqueId, getId() ); + } + + public TestDescriptor doDiscover(EngineDiscoveryRequest discoveryRequest, UniqueId uniqueId) { final BytecodeEnhancedEngineDescriptor engineDescriptor = new BytecodeEnhancedEngineDescriptor( (JupiterEngineDescriptor) new JupiterTestEngine().discover( discoveryRequest, uniqueId ) ); @@ -235,8 +261,12 @@ protected JupiterEngineExecutionContext createExecutionContext(ExecutionRequest } private JupiterConfiguration getJupiterConfiguration(ExecutionRequest request) { - JupiterEngineDescriptor engineDescriptor = (JupiterEngineDescriptor) request.getRootTestDescriptor(); - return engineDescriptor.getConfiguration(); + if ( request.getRootTestDescriptor() instanceof JupiterEngineDescriptor descriptor ) { + return descriptor.getConfiguration(); + } + else { + return null; + } } public Optional getGroupId() { @@ -278,8 +308,8 @@ public Optional getRawConfigurationParameter(String s) { } @Override - public Optional getRawConfigurationParameter(String s, Function function) { - return configuration.getRawConfigurationParameter( s, function ); + public Optional getRawConfigurationParameter(String key, Function transformer) { + return configuration.getRawConfigurationParameter( key, transformer ); } @Override @@ -353,8 +383,8 @@ public TestInstantiationAwareExtension.ExtensionContextScope getDefaultTestInsta } @Override - public OutputDirectoryProvider getOutputDirectoryProvider() { - return configuration.getOutputDirectoryProvider(); + public OutputDirectoryCreator getOutputDirectoryCreator() { + return configuration.getOutputDirectoryCreator(); } } diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFilterExtension.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFilterExtension.java index 5e0667e2d0cc..a286bef1c23b 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFilterExtension.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/DialectFilterExtension.java @@ -19,7 +19,7 @@ import org.jboss.logging.Logger; /** - * JUnit 5 extension used to add {@link RequiresDialect} and {@link SkipForDialect} + * JUnit Jupiter extension used to add {@link RequiresDialect} and {@link SkipForDialect} * handling * * @author Steve Ebersole diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/FailureExpectedExtension.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/FailureExpectedExtension.java index 0f280fb40cfe..b8ac9dcbc374 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/FailureExpectedExtension.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/FailureExpectedExtension.java @@ -16,7 +16,7 @@ import org.jboss.logging.Logger; /** - * JUnit 5 extension used to support {@link FailureExpected} handling + * JUnit Jupiter extension used to support {@link FailureExpected} handling * * @author Steve Ebersole */ diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/NotImplementedYetExtension.java b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/NotImplementedYetExtension.java index 45469645a007..c3dd9bf96c9e 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/NotImplementedYetExtension.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/orm/junit/NotImplementedYetExtension.java @@ -19,7 +19,7 @@ import static org.hibernate.testing.orm.junit.FailureExpectedExtension.failureExpectedValidation; /** - * JUnit 5 extension used to support {@link NotImplementedYet} handling + * JUnit Jupiter extension used to support {@link NotImplementedYet} handling * * @author Jan Schatteman */ diff --git a/local-build-plugins/src/main/groovy/local.java-module.gradle b/local-build-plugins/src/main/groovy/local.java-module.gradle index 003186fa84c2..bde0c34fee9e 100644 --- a/local-build-plugins/src/main/groovy/local.java-module.gradle +++ b/local-build-plugins/src/main/groovy/local.java-module.gradle @@ -52,13 +52,13 @@ dependencies { } // JUnit dependencies made up of: - // * JUnit 5 - // * the Jupiter engine which runs JUnit 5 based tests + // * JUnit (version 5 or later) + // * the Jupiter engine which runs JUnit 6 based tests // * the "vintage" engine - which runs JUnit 3 and 4 based tests - testImplementation testLibs.junit5Api - testImplementation testLibs.junit5Engine - testImplementation testLibs.junit5Params - testImplementation testLibs.junit5Launcher + testImplementation testLibs.junitJupiterApi + testImplementation testLibs.junitJupiterEngine + testImplementation testLibs.junitJupiterParams + testImplementation testLibs.junitJupiterLauncher testImplementation testLibs.junit4 testImplementation testLibs.junit4Engine testImplementation testLibs.assertjCore @@ -212,6 +212,8 @@ tasks.withType( Test.class ).each { test -> test.maxHeapSize = '3G' + // Enable bytecode enhanced engine: + test.systemProperties['hibernate.testing.bytecode.enhancement.extension.engine.enabled'] = true test.systemProperties['hibernate.test.validatefailureexpected'] = true test.systemProperties['hibernate.highlight_sql'] = false test.systemProperties += System.properties.findAll { it.key.startsWith( "hibernate." ) } diff --git a/migration-guide.adoc b/migration-guide.adoc index e0f69197d283..449b28fe688c 100644 --- a/migration-guide.adoc +++ b/migration-guide.adoc @@ -103,6 +103,51 @@ Interestingly, this now also aligns with handling for auto-flush events which al The behavior of `noInterceptor()` for `SharedSessionBuilder` and (the new) `SharedStatelessSessionBuilder` was aligned with the preexisting semantics of this method on `SessionBuilder` and `StatelessSessionBuilder`. The previous behavior may be recovered by calling `noSessionInterceptorCreation()`. +[[test-util-bytecodeenhanced-engine]] +=== JUnit `BytecodeEnhancedTestEngine` + +With this version, `BytecodeEnhancedTestEngine` will be disabled by default. +To be able to run the tests annotated with `@BytecodeEnhanced`, this engine has to be explicitly enabled via a system property: + +[source, properties] +---- +hibernate.testing.bytecode.enhancement.extension.engine.enabled=true +---- + +For a Maven-based project this can be done as part of the failsafe/surefire plugin configuration: + +[source, xml] +---- + + org.apache.maven.plugins + maven-surefire-plugin + + + true + + + + + + +---- + +While for a Gradle-based project this can be done in multiple ways, it essentially comes down to configuring the +link:https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html#org.gradle.api.tasks.testing.Test:systemProperties[`systemProperties`] +of a `Test` task: + +[source, groovy] +---- +tasks.withType(Test.class) { + // Enable bytecode enhanced engine: + systemProperties.systemProperties['hibernate.testing.bytecode.enhancement.extension.engine.enabled'] = true + // Any other test task configurations + // ... +} +---- + +Also, this engine is expected to only work with the exact version of JUnit that `org.hibernate.orm:hibernate-testing` depends on. +While it may work with other versions as well, there is no guarantee of that. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ // DDL changes @@ -120,3 +165,9 @@ Such changes typically do not impact programs using a relational schema managed This section describes changes to dependencies used by Hibernate ORM. +[[junit6]] +=== JUnit 6 update + +Hibernate ORM test utils distributed as `org.hibernate.orm:hibernate-testing` are now based on JUnit 6.0. +In general, this update is compatible with previous JUnit 5 versions unless the tests depended on the +<>. diff --git a/settings.gradle b/settings.gradle index 10de0fcb8694..4e6dbfd1f2e7 100644 --- a/settings.gradle +++ b/settings.gradle @@ -167,9 +167,9 @@ dependencyResolutionManagement { library( "jaxb", "org.glassfish.jaxb", "jaxb-runtime" ).versionRef( jaxbRuntimeVersion ) } testLibs { - def junit5Version = version "junit5", "5.13.4" + def junitJupiterVersion = version "junitJupiter", "6.0.0" def junit4Version = version "junit4", "4.13.2" - def junit5LauncherVersion = version "junit5Launcher", "1.13.4" + def junitJupiterLauncherVersion = version "junitJupiterLauncher", "6.0.0" def assertjVersion = version "assertj", "3.26.3" def hamcrestVersion = version "hamcrest", "3.0" @@ -189,11 +189,11 @@ dependencyResolutionManagement { library( "validator", "org.hibernate.validator", "hibernate-validator" ).versionRef( hibernateValidatorVersion ) - library( "junit5Api", "org.junit.jupiter", "junit-jupiter-api" ).versionRef( junit5Version ) - library( "junit5Engine", "org.junit.jupiter", "junit-jupiter-engine" ).versionRef( junit5Version ) - library( "junit5Params", "org.junit.jupiter", "junit-jupiter-params" ).versionRef( junit5Version ) - library( "junit4Engine", "org.junit.vintage", "junit-vintage-engine" ).versionRef( junit5Version ) - library( "junit5Launcher", "org.junit.platform", "junit-platform-launcher" ).versionRef( junit5LauncherVersion ) + library( "junitJupiterApi", "org.junit.jupiter", "junit-jupiter-api" ).versionRef( junitJupiterVersion ) + library( "junitJupiterEngine", "org.junit.jupiter", "junit-jupiter-engine" ).versionRef( junitJupiterVersion ) + library( "junitJupiterParams", "org.junit.jupiter", "junit-jupiter-params" ).versionRef( junitJupiterVersion ) + library( "junit4Engine", "org.junit.vintage", "junit-vintage-engine" ).versionRef( junitJupiterVersion ) + library( "junitJupiterLauncher", "org.junit.platform", "junit-platform-launcher" ).versionRef( junitJupiterLauncherVersion ) library( "junit4", "junit", "junit" ).versionRef( junit4Version ) library( "assertjCore", "org.assertj", "assertj-core" ).versionRef( assertjVersion ) diff --git a/test-case-guide.adoc b/test-case-guide.adoc index 8a22f93f1ba4..fadfe7d96280 100644 --- a/test-case-guide.adoc +++ b/test-case-guide.adoc @@ -13,10 +13,10 @@ There are a number of tenants that make up a good test case as opposed to a poor * (V)erifiable - The test should actually reproduce the problem being reported. -[[junit5]] -== JUnit 5 extensions +[[junit-jupiter]] +== [[junit5]] JUnit Jupiter (6) extensions -JUnit 5 offers better support for integration, compared to JUnit 4, via https://junit.org/junit5/docs/current/user-guide/#extensions[extensions]. Hibernate builds on those concepts in its `hibernate-testing` module allowing set up of test fixtures using annotations. The following sections describe the Hibernate extensions. +JUnit Jupiter offers better support for integration, compared to JUnit 4, via https://docs.junit.org/current/user-guide[extensions]. Hibernate builds on those concepts in its `hibernate-testing` module allowing set up of test fixtures using annotations. The following sections describe the Hibernate extensions. NOTE: The extensions exist in the `org.hibernate.testing.orm.junit` package, as opposed to the older `org.hibernate.testing.junit4` package used with JUnit 4. @@ -29,7 +29,7 @@ Manages a `ServiceRegistry` as part of the test lifecycle. 2 in fact, depending `@BootstrapServiceRegistry`:: configures Hibernate's bootstrap `BootstrapServiceRegistry` which manages class-loading, etc. `@BootstrapServiceRegistry` is used to provide Java services and Hibernate `Integrator` implementations for the test. `@ServiceRegistry`:: configures Hibernate's standard `StandardServiceRegistry`. `@ServiceRegistry` is used to provide settings, contributors, services, etc. -Also exposes `ServiceRegistryScope` via JUnit 5 `ParameterResolver`. `ServiceRegistryScope` allows +Also exposes `ServiceRegistryScope` via JUnit's `ParameterResolver`. `ServiceRegistryScope` allows access to the managed `ServiceRegistry` from tests and callbacks. ``` @@ -191,7 +191,7 @@ The distinction with `@Jpa` is that `EntityManagerExtension` uses the JPA-define == JUnit 4 -Historically, Hibernate used JUnit 4 for its test suite. Since the release of https://junit.org/junit5/[JUnit 5], we've moved to using the testing approach outlined in <>. However, many existing tests still use the legacy JUnit 4 based infrastructure (boilerplate) based on "test templates". +Historically, Hibernate used JUnit 4 for its test suite. Since the release of https://junit.org/junit5/[JUnit 5], we've moved to using the testing approach outlined in <>. However, many existing tests still use the legacy JUnit 4 based infrastructure (boilerplate) based on "test templates". === Test templates diff --git a/tooling/hibernate-gradle-plugin/hibernate-gradle-plugin.gradle b/tooling/hibernate-gradle-plugin/hibernate-gradle-plugin.gradle index 4c893be0e882..f6c6d6eb37ce 100644 --- a/tooling/hibernate-gradle-plugin/hibernate-gradle-plugin.gradle +++ b/tooling/hibernate-gradle-plugin/hibernate-gradle-plugin.gradle @@ -32,10 +32,10 @@ dependencies { testImplementation gradleTestKit() testImplementation testLibs.assertjCore - testImplementation testLibs.junit5Api + testImplementation testLibs.junitJupiterApi - testRuntimeOnly testLibs.junit5Engine - testRuntimeOnly testLibs.junit5Launcher + testRuntimeOnly testLibs.junitJupiterEngine + testRuntimeOnly testLibs.junitJupiterLauncher } gradlePlugin {