junit5 icon indicating copy to clipboard operation
junit5 copied to clipboard

Introduce `@DependsOn` to prioritize test method execution order

Open duckladydinh opened this issue 6 years ago • 20 comments

@Update: Now it works exactly like TestNG, which means if A depends on B, and B is disabled, then A is disabled as well.

Hi everyone,

I am creating a pull request for this feature. It should work similar to TestNG (@Test(dependsOn = ...)) but it will not disable the test if some test fails. It just gives methods a priority like @Order.

It would be great if someone can give me some advice how to improve it.

Thank you :)

duckladydinh avatar Feb 09 '19 05:02 duckladydinh

Tentatively slated for 5.5 M1 for the purpose of team discussion.

sbrannen avatar Feb 09 '19 09:02 sbrannen

Hi @duckladydinh,

Thanks for opening the issue and submitting the PR!

I am creating a pull request for this feature. It should work similar to TestNG (@Test(dependsOn = ...)) but it will not disable the test if some test fails. It just gives methods a priority like @Order.

Although I think there is merit in mere "dependent ordering" as in the PR, I think it would be worth investigating the possibility for "not executing" methods if a method that they depend on fails.

For example, if C depends on A and A fails, then C should be aborted. That's basically what TestNG does, and I think it might be possible to implement this elegantly in JUnit Jupiter by implementing the TestWatcher API introduced in JUnit Jupiter 5.4. Of course, I have not tried to implement it myself, so I'm just thinking out loud here.

sbrannen avatar Feb 09 '19 09:02 sbrannen

Hi @sbrannen , thank you for the suggestion. I think I have something done already based on your suggestion. My design is to keep the DependsOnAnnotation as it is, and add a separate TestWatcher :).

duckladydinh avatar Feb 11 '19 02:02 duckladydinh

Hi is there any update on when this PR might be merged in. There hasn't been any follow up since end of last year. Thank you.

thespags avatar Aug 26 '20 20:08 thespags

This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. Thank you for your contribution.

stale[bot] avatar Jun 19 '22 20:06 stale[bot]

Hi. I wanted to check in if there is any update or concerns? This is one of the features available in TestNG that I miss when working in JUnit5. It helps isolate problems in tests when you have good dependency management.

spags-twilio avatar Jun 19 '22 22:06 spags-twilio

Also checking about this, this feature would be very usable, is it going to be merged?

fogrid avatar Jul 12 '22 09:07 fogrid

Any news here?

ahoehma avatar Jun 09 '23 06:06 ahoehma

@ahoehma, this issue still has the waiting-for-interest label.

sbrannen avatar Jun 09 '23 08:06 sbrannen

This feature would be very useful

jzhang-SD avatar Jan 24 '24 22:01 jzhang-SD

I am still interested.

thespags avatar Jan 24 '24 22:01 thespags

I'm not sure what happened here, but this would be a useful feature to have. It's something that TestNG can do, and the lack of support makes migrating from TestNG to JUnit difficult.

ericparton avatar Mar 01 '24 21:03 ericparton