-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Introduce @BeforeSuite
and @AfterSuite
annotations
#456
Comments
Related to #163. There's not always an easy way to control what's considered a "Suite". If you look at the Maven plugin, it controls the inclusion/exclusion of tests via XML. The If there was always a declarative way to run a suite, I'd say that |
Related to #19 |
In my consideration "Suite" can be defined via:
In all those cases I would expect that |
I agree with everything @ondrejlerch brings up |
@ondrejlerch How would JUnit find The |
@marcphilipp you could consider a solution such as Jandex, which provides you an index over all annotations |
Well, in any case, it has to be obvious for test authors where JUnit will actually look for these annotations, i.e. if they will be applied when they execute a test class. |
I see an easy way to implement an extension point for 3a -- which frames the all tests executed by the Jupiter engine with a "before the first" and "after the last" callback. Pseudo-code for JupiterTestEngine: @Override
public final void execute(ExecutionRequest request) {
// TODO context = createExecutionContext(request);
// try {
// TODO callBeforeExecutionCallbacks(context);
new HierarchicalTestExecutor<>(request, context).execute();
// } finally {
// TODO callAfterExecutionCallbacks(context);
// }
} |
For the record, I actually would not use the annotation specifically. I am more interested in the corresponding Extension (especially AfterSuiteCallback). I was just answering the general question of "finding annotations". That is what Jandex excels at, whether you want to use it or not... |
I’m fine with adding an extension point that uses the existing registration mechanisms. That should work for everything except Maven Surefire... see #1113. |
As I would never use Maven ever again, I can live with that ;) But yes, that is exactly what would work best for us:
|
Started working on a PR that introduces |
@marcphilipp If we use JUnit 5 with Spring then Spring Context should be initialized first, then
Solution should work with IDE, Maven and Gradle as those are most typical tools for test execution. I agree with @sebersole that Maven is not cutting edge, however, if Maven Surefire would not work then please suggest what would work in Maven as it is widely used. Thanks! |
@sormuras Thanks so much for starting on this. |
I'm also fine with the idea of introducing new But... we'll have to work on the names. 😉 That and the implementation and semantics of course. |
The JUnit 5 hooks weren't actually usable for lifecycle control, as they ran before each test class. As JUnit 5 does not provide hooks to run code easily before a suite (junit-team/junit5#456), lets fall back to the singleton container provided by Testcontainers. (https://www.testcontainers.org/test_framework_integration/manual_lifecycle_control/#singleton-containers) The Ryuk container will take care of removing any stale containers. It was noticed that we do not need to set "withReuse(true)", as the container is shared between test classes (singleton pattern) and creating clean instances on each test run is fine for now.
The JUnit 5 hooks weren't actually usable for lifecycle control, as they ran before each test class. As JUnit 5 does not provide hooks to run code easily before a suite (junit-team/junit5#456), lets fall back to the singleton container provided by Testcontainers. (https://www.testcontainers.org/test_framework_integration/manual_lifecycle_control/#singleton-containers) The Ryuk container will take care of removing any stale containers. It was noticed that we do not need to set "withReuse(true)", as the container is shared between test classes (singleton pattern) and creating clean instances on each test run is fine for now.
Team decision: Investigate the feasibility of adding |
Hi @marcphilipp , Please feedback what is the alternative of BeforeSuite and AfterSuite , in order to create 1 consolidated Extend Report across all Test Classes . Regards , |
@YomnaZidan @praveenreddynarala I am facing same issue as you both with extent report generation. Did you guys find any alternatives, if so can you please share. That would be a great help. Thanks 🙏 |
@kishkk84 @YomnaZidan you can take a look at my solution implemented based on workaround using ClosableResource (see 456 comment) |
Junit5 does not contain the same suite level resource as junit4 [based on stackoverflow answer][stack] and [open issue][issue], so remove mention of it from `DropwizardAppExtension` from the javadocs to avoid any confusion. [stack]: https://stackoverflow.com/a/50678092/433785 [issue]: junit-team/junit5#456
We have the same requirement. In JUnit 4, we were using an |
Can we not follow what the definition of suite is as per TestNG.. https://testng.org/doc/documentation-main.html @BeforeSuite |
@BeforeSuite
and @AfterSuite
annotations
@marcphilipp Is there any update to this?
I've tried a solution of creating a custom extension class with BeforeAllCallback and then extending my suite with it, but no success. The Suite runs all feature files in my features package and I need the BeforeAll method to do database cleanup before running the features.. |
@MaudeVanhengel What we endet up doing is a
We add the profile to the test execution and write our "BeforeAllCallback"-Code in the annoated methods. You could also use the InitializingBean or listen for spring application events (e.g. ContextStartedEvent) and execute code once the context is fully started. The problem with the Callbacks is, that you don't have access to the spring application context to for example initialize the database using spring repositories. WARNING: |
I suggest that
@BeforeSuite
and@AfterSuite
annotations should be added to JUnit 5.Obviously they should execute before and after the whole suite.
Or is there some other mechanism to accomplish that?
I suggest that there should not be static restriction, i.e. also non-static methods could be annotated with
@BeforeSuite
and@AfterSuite
.I personally prefer non-static as we use Spring in our tests and want to use injected beans in
@BeforeSuite
method.The text was updated successfully, but these errors were encountered: