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

Lifecycle annotations migration #7

Open
Philzen opened this issue Jun 14, 2024 · 1 comment
Open

Lifecycle annotations migration #7

Philzen opened this issue Jun 14, 2024 · 1 comment
Labels
Feature New feature or request must-have

Comments

@Philzen
Copy link
Owner

Philzen commented Jun 14, 2024

All of these need to be migrated:

  • @BeforeSuite: The annotated method will be run before all tests in this suite have run.
  • @AfterSuite: The annotated method will be run after all tests in this suite have run.
  • @BeforeTest: The annotated method will be run before any test method belonging to the classes inside the tag is run.
  • @AfterTest: The annotated method will be run after all the test methods belonging to the classes inside the tag have run.
  • @BeforeGroups: The list of groups that this configuration method will run before. This method is guaranteed to run shortly before the first test method that belongs to any of these groups is invoked.
  • @AfterGroups: The list of groups that this configuration method will run after. This method is guaranteed to run shortly after the last test method that belongs to any of these groups is invoked.
  • @BeforeClass: The annotated method will be run before the first test method in the current class is invoked.
  • @AfterClass: The annotated method will be run after all the test methods in the current class have been run.
  • @BeforeMethod: The annotated method will be run before each test method.
  • @AfterMethod: The annotated method will be run after each test method.

(from the TestNG documentation)

These may be easily migrated using existing recipes:

https://github.com/MBoegers/migrate-testngtojupiter-rewrite/blob/b8031036df2c2207a1263a5b9f624c7703546024/src/main/resources/META-INF/rewrite/rewrite.yml#L20-L35

@Philzen Philzen added Feature New feature or request must-have labels Jun 14, 2024
@Philzen
Copy link
Owner Author

Philzen commented Jun 15, 2024

It may be relevant to investigate that the inheritance behavior of the JUnit5 replacements is identical to TestNG:

The annotations above will also be honored (inherited) when placed on a superclass of a TestNG class. This is useful for example to centralize test setup for multiple test classes in a common superclass.

In that case, TestNG guarantees that the "@before" methods are executed in inheritance order (highest superclass first, then going down the inheritance chain), and the "@after" methods in reverse order (going up the inheritance chain).

See also: https://web.archive.org/web/20160304173137/http://beust.com/weblog2/archives/000170.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New feature or request must-have
Projects
Status: Ready
Development

No branches or pull requests

1 participant