Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Helidon MicroProfile Testing Improvements
Description
Test Instance Creation
The test instances are now created by CDI exclusively for both JUnit and TestNG.
This normalizes the use of CDI across both test frameworks.
Notable changes:
resetPerTest = true
has been removed.The following code now works:
The following code now works:
JUnit Instance Lifecycle
Support for JUnit's lifecycle has been implemented.
I.e.
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
(default)@TestInstance(TestInstance.Lifecycle.PER_METHOD)
The default is
PER_CLASS
and is set via@HelidonTest
in order to retain compatibility.Notable changes:
@TestInstance
have been removed.The following code now works:
Improved Meta Annotation Support
The support for meta annotation has been improved. It is now possible to compose using all the MicroProfile Testing annotations.
E.g.
Default AddBean Scope
Updated the
@AddBean
annotation to use an "undefined" default scope value.This allows to use the scope defined on the bean class, unless the scope attribute is explicitly set.
Implicit CDI Container Reset
Individual test methods can now request a dedicated CDI container without using
@HelidonTest(resetPerTest = true)
.Using the following annotations on methods creates a dedicated CDI container:
AddBean
AddExtension
DisableDiscovery
AddJaxRs
AddConfig
AddConfigBlock
Configuration
By default the methods that share the "class" container are grouped in order to prevent unnecessary restarts.
When using JUnit, a default method orderer is used to implement the grouping:
HelidonImplicitResetOrderer
.Note that if a test class defines an orderer, the grouping must be done manually in order to prevent unnessary restarts.
When using TestNG, the methods are grouped and then sorted by priority.
I.e. The priority takes precedence.
Lazy CDI container Startup
The test class is now proxied (using ByteBuddy) in order to start the CDI container just in time.
This makes the extension order insignificant and thus improves the user experience with TestContainers.
In the example below, the Docker container is started before the CDI container:
Automatic CDI Initializer Configuration
When using
@Configuration(useExisting = true)
the requirement to specify the CDI initializer configuration has been removed:API changes
A new module:
io.helidon.microprofile.testing
has been created to share the API and implementation between the JUnit and TestNG integrations.The following annotations are added:
The following annotations are deprecated:
This addresses the API duplication that currently exists between the JUnit and TestNG integrations.
The deprecated APIs will remain in 4.x and will be removed in 5.0.
The JUnit extension class is now public and usable with
@ExtendsWith
by users directly:io.helidon.microprofile.testing.junit5.HelidonJunitExtension
3rd Party Changes
The new module (
io.helidon.microprofile.testing:helidon-microprofile-testing
) adds a dependency onnet.bytebuddy:byte-buddy
. This dependency is already managed in the dependencies BOM.Documentation
The MicroProfile testing documentation has been updated.