0

Please support me in understanding and over coming confusion of when to use @IncludeEngines and when to use @ExtendWith in JUnit 5.

Apologies if this question is too basic.

Thank you in advance.

glytching
  • 44,936
  • 9
  • 114
  • 120
santosh
  • 43
  • 8

1 Answers1

2

@ExtendWith is used to register custom extensions

In terms of JUnit4 constructs: @RunWith, @Rule and @ClassRule have all been superseded by @ExtendWith. Although JUnit 5 does retain limited support for rules, the JUnit team's strong advice is to move to using @ExtendWith.

There are examples of some common JUnit4 rules re-implemented as JUnit5 extensions here.

@IncludeEngines specifies the org.junit.platform.engine.TestEngine implementation(s) to be included when running a test suite on the JUnit Platform. Although this is in org.junit.platform.suite.api and is therefore available for developers to use, I can't think of any situation in which you'd need to use it. It could be used to engage a specific engine e.g. the vintage engine rather than the JupiterTestEngine but that would imply a need to run tests in a JUnit4 environment and this can be achieved using @RunWith(JUnitPlatform.class).

Do you think you need to use @IncludeEngines? If so, I'd suggest explaining why you think you need to use it and you might find that there are other ways to use JUnit5 which doe not require use of @IncludeEngines.

glytching
  • 44,936
  • 9
  • 114
  • 120
  • 1
    like glytching said, we sometimes need to use @IncludeEngines to execute test with engine like cucumber engine – soung Apr 17 '22 at 18:20
  • https://github.com/cucumber/cucumber-jvm/tree/main/cucumber-junit-platform-engine#suites-with-different-configurations – dbaltor Apr 04 '23 at 23:36