You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@ExtendWith annotation attached to a custom "before all" annotation is not respected.
When it is attached to an annotation interface with a "@testtemplate", it lets JUnit use an extension specified by it.
However, when it is attached to an interface with @BeforeAll annotation, JUnit doesn't use the extension and keep performing the default behaviour, apparently.
Expectation:
If the extension specified by the "@ExtendWith" is implementing "before all callback extension" , the beforeAll(ExtensionContext) method should be called back.
That is, with the code example I placed in "Steps to reproduce", it should print following.
beforeAll(ExtensionContext) is called
beforeAll is called
customBeforeAll is called
test is called
Actual:
The beforeAll(ExtensionCotext) of the provided extension is not called back.
That is, we see a following output when we run the test in the "Steps to reproduce" section.
beforeAll is called
customBeforeAll is called
test is called
Steps to reproduce
Run following class from your IDE. (in my case IntelliJ).
packagecom.github.dakusui.jcunitx.engine.junit5;
importorg.junit.jupiter.api.BeforeAll;
importorg.junit.jupiter.api.Test;
importorg.junit.jupiter.api.extension.BeforeAllCallback;
importorg.junit.jupiter.api.extension.ExtendWith;
importorg.junit.jupiter.api.extension.ExtensionContext;
importjava.lang.annotation.Retention;
importstaticjava.lang.annotation.RetentionPolicy.RUNTIME;
publicclassExample {
@BeforeAll@Retention(RUNTIME)
@ExtendWith(CustomBeforeAllExtension.class)
public @interface CustomBeforeAll {
}
publicstaticclassCustomBeforeAllExtensionimplementsBeforeAllCallback {
@OverridepublicvoidbeforeAll(ExtensionContextcontext) {
System.out.println("beforeAll(ExtensionContext) is called");
}
}
@BeforeAllpublicstaticvoidbeforeAll() {
System.out.println("beforeAll is called");
}
@CustomBeforeAllpublicstaticvoidcustomBeforeAll() {
System.out.println("customBeforeAll is called");
}
@Testpublicvoidtest() {
System.out.println("test is called");
}
}
Context
Used versions (Jupiter/Vintage/Platform): Jupiter 5.7.1
Build Tool/IDE: IntelliJ
Deliverables
...
The text was updated successfully, but these errors were encountered:
sbrannen
changed the title
@ExtendsWith is not respected if attached to custom "before all" annotation
Support extension registration on lifecycle methods
Feb 18, 2021
sbrannen
changed the title
Support extension registration on lifecycle methods
Support declarative extension registration on lifecycle methods
Feb 18, 2021
Team decision: We don't want to add another way to register extensions, in particular since BeforeAllCallbacks should be registered on the class-level.
@ExtendWith
annotation attached to a custom "before all" annotation is not respected.When it is attached to an annotation interface with a "@testtemplate", it lets JUnit use an extension specified by it.
However, when it is attached to an interface with
@BeforeAll
annotation, JUnit doesn't use the extension and keep performing the default behaviour, apparently.Expectation:
If the extension specified by the "@ExtendWith" is implementing "before all callback extension" , the
beforeAll(ExtensionContext)
method should be called back.That is, with the code example I placed in "Steps to reproduce", it should print following.
Actual:
The
beforeAll(ExtensionCotext)
of the provided extension is not called back.That is, we see a following output when we run the test in the "Steps to reproduce" section.
Steps to reproduce
Run following class from your IDE. (in my case IntelliJ).
Context
Deliverables
The text was updated successfully, but these errors were encountered: