Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support declarative extension registration on lifecycle methods #2555

Closed
1 task
dakusui opened this issue Feb 18, 2021 · 3 comments
Closed
1 task

Support declarative extension registration on lifecycle methods #2555

dakusui opened this issue Feb 18, 2021 · 3 comments

Comments

@dakusui
Copy link

dakusui commented Feb 18, 2021

@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).

package com.github.dakusui.jcunitx.engine.junit5;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.BeforeAllCallback;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.ExtensionContext;

import java.lang.annotation.Retention;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

public class Example {
  @BeforeAll
  @Retention(RUNTIME)
  @ExtendWith(CustomBeforeAllExtension.class)
  public @interface CustomBeforeAll {
  }

  public static class CustomBeforeAllExtension implements BeforeAllCallback {
    @Override
    public void beforeAll(ExtensionContext context) {
      System.out.println("beforeAll(ExtensionContext) is called");
    }
  }

  @BeforeAll
  public static void beforeAll() {
    System.out.println("beforeAll is called");
  }

  @CustomBeforeAll
  public static void customBeforeAll() {
    System.out.println("customBeforeAll is called");
  }

  @Test
  public void test() {
    System.out.println("test is called");
  }
}

Context

  • Used versions (Jupiter/Vintage/Platform): Jupiter 5.7.1
  • Build Tool/IDE: IntelliJ

Deliverables

  • ...
@sbrannen 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 sbrannen added this to the 5.8 M2 milestone Feb 18, 2021
@sbrannen
Copy link
Member

Tentatively slated for 5.8 M2 solely for the purpose of team discussion

@sbrannen sbrannen changed the title Support extension registration on lifecycle methods Support declarative extension registration on lifecycle methods Feb 18, 2021
@marcphilipp
Copy link
Member

Team decision: We don't want to add another way to register extensions, in particular since BeforeAllCallbacks should be registered on the class-level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants