If I use more than one extension with JUnit 5, whats the order? Ideally the order int the @ExtendsWith
annotation is respected, but I could not find any documentation about that.
Example:
@ExtendWith({SpringExtension.class, InitH2.class})
public class VmRepositoryIntegrationTest {
// Test implemenations
}
So in this example I need Spring to set up the DB connection before I cann initialize the DB.
From §5.2.1 of the JUnit 5 User Guide:
...
Multiple extensions can be registered together like this:
@ExtendWith({ DatabaseExtension.class, WebServerExtension.class }) class MyFirstTests { // ... }
As an alternative, multiple extensions can be registered separately like this:
@ExtendWith(DatabaseExtension.class) @ExtendWith(WebServerExtension.class) class MySecondTests { // ... }
Extension Registration Order
Extensions registered declaratively via
@ExtendWith
will be executed in the order in which they are declared in the source code. For example, the execution of tests in bothMyFirstTests
andMySecondTests
will be extended by theDatabaseExtension
andWebServerExtension
, in exactly that order.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With