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

AfterGroups config annotation does not consider retries for tests #2684

Closed
2 of 7 tasks
krmahadevan opened this issue Nov 28, 2021 · 0 comments · Fixed by #2690
Closed
2 of 7 tasks

AfterGroups config annotation does not consider retries for tests #2684

krmahadevan opened this issue Nov 28, 2021 · 0 comments · Fixed by #2690

Comments

@krmahadevan
Copy link
Member

krmahadevan commented Nov 28, 2021

TestNG Version

Note: only the latest version is supported
7.4.0

Expected behaviour

@AfterGroups configuration method should wait for all tests (including the retried tests) to finish.

Actual behaviour

@AfterGroups configuration method runs before failed test retries are triggered.

Is the issue reproducible on runner?

  • Shell
  • Maven
  • Gradle
  • Ant
  • Eclipse
  • IntelliJ
  • NetBeans

Test case sample

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

import static org.testng.Assert.assertTrue;

import java.util.ArrayList;
import java.util.List;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;

public class SampleTestClassWithGroupConfigs {

  public static final List<String> logs = new ArrayList<>();

  @BeforeGroups("p1")
  public void beforeGroups() {
    logs.add("beforeGroups");
  }

  @Test(groups = "p1", retryAnalyzer = RerunAnalyzer.class)
  public void testMethod() {
    logs.add("testMethod");
    RerunAnalyzer.secondTestRetryCount++;
    assertTrue(RerunAnalyzer.secondTestRetryCount > RerunAnalyzer.maxRetryCount);
  }

  @AfterGroups("p1")
  public void afterGroups() {
    logs.add("afterGroups");
  }
}
import org.testng.IRetryAnalyzer;
import org.testng.ITestResult;

public class RerunAnalyzer implements IRetryAnalyzer {

    public static final int maxRetryCount = 1;
    public static int secondTestRetryCount = 0;
    private int retryCount = 0;

    @Override
    public boolean retry(ITestResult iTestResult) {
        if (retryCount < maxRetryCount) {
            retryCount++;
            return true;
        }
        return false;
    }
}
import static org.testng.Assert.assertEquals;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.testng.TestNG;
import org.testng.annotations.Test;
import org.testng.xml.XmlClass;
import org.testng.xml.XmlGroups;
import org.testng.xml.XmlRun;
import org.testng.xml.XmlSuite;
import org.testng.xml.XmlTest;

public class IssueTest {

  @Test
  public void testRetriedTestsWithGroupConfigs() {
    XmlSuite xmlSuite = new XmlSuite();
    xmlSuite.setName("groups_suite");
    xmlSuite.setVerbose(2);
    XmlTest xmlTest = new XmlTest(xmlSuite);
    xmlTest.setName("groups_test");
    XmlGroups xmlGroups = new XmlGroups();
    XmlRun xmlRun = new XmlRun();
    xmlRun.onInclude("p1");
    xmlGroups.setRun(xmlRun);
    xmlTest.setGroups(xmlGroups);
    xmlTest.setClasses(
        Collections.singletonList(
            new XmlClass(SampleTestClassWithGroupConfigs.class)
        )
    );
    TestNG testng = new TestNG();
    testng.setXmlSuites(Collections.singletonList(xmlSuite));
    testng.run();
    List<String> actual = SampleTestClassWithGroupConfigs.logs;
    List<String> expected = Arrays.asList("beforeGroups", "testMethod", "testMethod",
        "afterGroups");
    assertEquals(actual, expected, actual + " didn't match elements in expected list" + expected);
  }
}

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.

Reported from the TestNG dev forum

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

Successfully merging a pull request may close this issue.

1 participant