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

documentation incorrect in AfterTest.java #2947

Open
6 tasks
jjfrankovich opened this issue Aug 14, 2023 · 2 comments
Open
6 tasks

documentation incorrect in AfterTest.java #2947

jjfrankovich opened this issue Aug 14, 2023 · 2 comments

Comments

@jjfrankovich
Copy link

jjfrankovich commented Aug 14, 2023

TestNG Version

Note: only the latest version is supported
latest

Expected behavior

The documentation for alwaysRun should be corrected to show that alwaysRun is not required to run cleanup afer a failed test.

 /**
   * For before methods (beforeSuite, beforeTest, beforeTestClass and beforeTestMethod, but not
   * beforeGroups): if set to true, this configuration method will be run regardless of what groups
   * it belongs to. <br>
   * For after methods (afterSuite, afterClass, ...): if set to true, this configuration method will
   * be run even if the group does not match. alwaysRun=true is no longer required if a test fails, just a matching group is sufficient.
   *
   * @return the value (default false)
   */
  boolean alwaysRun() default false;

Actual behavior

https://github.com/testng-team/testng/blob/master/testng-core-api/src/main/java/org/testng/annotations/AfterTest.java

 /**
   * For before methods (beforeSuite, beforeTest, beforeTestClass and beforeTestMethod, but not
   * beforeGroups): if set to true, this configuration method will be run regardless of what groups
   * it belongs to. <br>
   * For after methods (afterSuite, afterClass, ...): if set to true, this configuration method will
   * be run even if one or more methods invoked previously failed or was skipped.
   *
   * @return the value (default false)
   */
  boolean alwaysRun() default false;

Is the issue reproducible on runner?

  • Shell
  • Maven
  • Gradle
  • Ant
  • Eclipse
  • [x ] IntelliJ
  • NetBeans

Test case sample

Please, share the test case (as small as possible) which shows the issue

  @BeforeTest
  public void beforeTest()
  {
    System.out.println("beforeTest");
  }

  @AfterTest
  public void afterTest()
  {
    System.out.println("afterTest");
  }

  public void failedAssert()
  {
    assertEquals(true, false);
  }

  public void failedAssertWithThrow()
  {
    new RuntimeException("test");
  }

Results:

d:\niagara\r414>test baja:HtmlUtilsTest.failedAssert

beforeTest
afterTest

*** TestNG Failure Summary ***
 TestNG Test Failed: failedAssert on Html Utils Test - expected [false] but found [true]

===============================================
bajaTest_HtmlUtilsTest
Total tests run: 1, Failures: 1, Skips: 0
===============================================

===============================================
Results of all run tests
Total tests run: 1, Failures: 1, Skips: 0
===============================================
d:\>test baja:HtmlUtilsTest.failedAssertWithThrow
...
beforeTest
afterTest

===============================================
bajaTest_HtmlUtilsTest
Total tests run: 1, Failures: 0, Skips: 0
===============================================

===============================================
Results of all run tests
Total tests run: 1, Failures: 0, Skips: 0
===============================================

Contribution guidelines

Incase you plan to raise a pull request to fix this issue, please make sure you refer our Contributing section for detailed set of steps.

@jjfrankovich
Copy link
Author

I was just informed that alwaysRun applies to previous AfterXXX method (and not test method failures), so it would be good to clarify that in the javadoc:

For before methods (beforeSuite, beforeTest, beforeTestClass and beforeTestMethod, but not
beforeGroups): if set to true, this configuration method will be run regardless of what groups
it belongs to.
For after methods (afterSuite, afterClass, ...): if set to true, this configuration method will
be run even if a previous after method failed.
@return the value (default false)

@juherr
Copy link
Member

juherr commented Aug 16, 2023

Thanks for the report. The way you run the test may have impacts.
How can we reproduce the behavior? I mean: what is the test command doing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants