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

Cucumber JUnit5 should support @BeforeAll, @AfterAll. Cucumber JUnit4 currently supports @BeforeClass, @AfterClass #2226

Closed
davidmelia opened this issue Feb 8, 2021 · 6 comments
Labels
♊ duplicate Duplicate of another issue ⚡ enhancement Request for new functionality

Comments

@davidmelia
Copy link

Hi,

I have a project showing the issue https://github.com/davidmelia/cucumber-junit5

Currently Cucumber JUnit 4 supports @BeforeClass/ @afterclass which is invaluable for starting embedded databases,etc

import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/resources/com/melia", plugin = {"pretty", "html:target/cucumber"})
public class CucumberJunit4Test {

  @BeforeClass
  public static void beforeClass() {
      System.out.println("****** Before Class JUnit4 *****");
  }
  @AfterClass
  public static void afterClass() {
      System.out.println("****** After Class JUnit4 *****");
  }
  
}

I am migrating to Cucumber JUnit5 and notice it doesn't support this:


import io.cucumber.junit.platform.engine.Cucumber;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;

@Cucumber
public class CucumberJunit5BeforeAllAfterAllTest {
  @BeforeAll
  public static void beforeAll() {
      System.out.println("****** Before All JUnit5 *****");
  }
  @AfterAll
  public static void afterAll() {
      System.out.println("****** After All JUnit5 *****");
  }
  
}

Further to this I cannot get around this by providing a custom extension

@Cucumber
@ExtendWith(value = JUnit5Extension.class)
public class CucumberJunit5ExtensionTest {
  
}

as the extension does not fire.

Could @BeforeAll, @afterall please be supported as migrating will be extremely difficult if not impossible.

Thanks

@mpkorstanje
Copy link
Contributor

Worth noting that unlike previous versions of JUnit, JUnit 5 consists of Jupiter, Vintage and the JUnit Platform. Jupiter and Vintage are like Cucumber test engines in the JUnit Platform. As such it is not possible to reuse features from Jupiter in Cucumber.

So ultimately this is a duplicate of #515 and that will be a while because it requires a pretty big rewrite of Cucumber.

@mpkorstanje mpkorstanje added ⚡ enhancement Request for new functionality ♊ duplicate Duplicate of another issue labels Feb 8, 2021
@davidmelia
Copy link
Author

@mpkorstanje thanks for the quick reply. What about supporting ExtendsWith:

@Cucumber
@ExtendWith(value = JUnit5Extension.class)
public class CucumberJunit5ExtensionTest {
  
}

is this still the same amount of effort?

@mpkorstanje
Copy link
Contributor

The extension model is also part of Jupiter and not really reusable. It is strongly tied to the assumption that there is exactly one instance of the class under test and that each test is a single method. Cucumber uses multiple classes with multiple methods in a single test.

@davidmelia
Copy link
Author

FYI for anyone interested I have created an example using the global hook example in https://github.com/davidmelia/cucumber-junit5/blob/main/src/test/java/com/melia/CucumberJunit5GlobalHookTest.java

@gitsaquib
Copy link

@hertzsprung
Copy link

FYI for anyone interested I have created an example using the global hook example in https://github.com/davidmelia/cucumber-junit5/blob/main/src/test/java/com/melia/CucumberJunit5GlobalHookTest.java

The @Cucumber annotation is deprecated, but you can configure a ConcurrentEventListener via Cucumber's plugin mechanism.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
♊ duplicate Duplicate of another issue ⚡ enhancement Request for new functionality
Projects
None yet
Development

No branches or pull requests

4 participants