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

Conflict beween config failure skips and listener forced exceptions #2721

Open
3 of 7 tasks
baubakg opened this issue Jan 25, 2022 · 1 comment
Open
3 of 7 tasks

Conflict beween config failure skips and listener forced exceptions #2721

baubakg opened this issue Jan 25, 2022 · 1 comment

Comments

@baubakg
Copy link

baubakg commented Jan 25, 2022

TestNG Version

7.5
(regression in regards to 7.4.0)

Expected behavior

If you throw a skip exception in one of your listeners whilst a BeforeX method has already failed, the state of the tests should be skipped (in 7.4.0 it was the case. The new skip overrode the configure issue)

Also we should not lose parameter/data provider data.

Actual behavior

Since 7.5 (Worked fine in 7.4.0 (despite #2522 )) If you throw a skip exception in one of your listeners whilst a BeforeX method has already failed, the state of the tests will switch to "Failed".

Another consequence of this is that if you use a data provider, the parameter will be lost in the ITestResult object .

Is the issue reproducible on runner?

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

Test case sample

In my examples bellow, My listener, DP_Listeners, throws a skip exception.

My test class MyTest has a beforeSuite method that contains a failing assertion.

(I have omitted my helper methods, but can add them if you need it)

   @Test
   public void problemTest() {

       // Rampup
       TestNG myTestNG = createTestNG();
       TestListenerAdapter tla = fetchTestResultsHandler(myTestNG);

       // Define suites
       XmlSuite mySuite = addSuitToTestNGTest(myTestNG, "Problem Test Suite");

       // Add listeners
       mySuite.addListener(DP_Listeners.class.getTypeName());

       // Create an instance of XmlTest and assign a name for it.
       XmlTest myTest = attachTestToSuite(mySuite, "Test config methods");

       myTest.setXmlClasses(Arrays.asList(new XmlClass(MyTest.class)));

       myTestNG.run();

       SoftAssert softAssertion = new SoftAssert();
       softAssertion.assertEquals(tla.getPassedTests().size(), 0, "No tests should be passed");
       softAssertion.assertEquals(tla.getSkippedTests().size(), 2, "All tests tests should be skipped");
       softAssertion.assertEquals(tla.getFailedTests().size(), 0, "No tests tests should be failed");
       
       if (tla.getFailedTests().size()>0) {
           softAssertion.assertEquals(tla.getFailedTests().get(0).getParameters().length, 1, "We should still keep our parameters");
       }
       softAssertion.assertAll();
   }    

My Listener

public class DP_Listeners implements ITestListener {

    @Override
    public void onTestStart(ITestResult result) {
        if (result.getName().equals("simpleTest1")) {
            throw new SkipException("Forced Skip");
        }
    }

}

My target test class:

public class MyTest {
    @BeforeSuite
    public void beforePhasedSuite() {
        int beforeValue = 13;

        Assert.assertEquals(beforeValue, 14);
    }
    
    @DataProvider (name = "myProvider")
    public Object[][] dpMethod() {
        return new Object [][] { {"P1"}};
    }
    
    @Test(dataProvider = "myProvider")
    public void simpleTest1(String s) {
        System.out.println("In test1 "+s);
    }
    
    @Test(dataProvider = "myProvider")
    public void simpleTest2(String s) {
        System.out.println("In test2 "+ s);
    }

}
@juherr juherr added this to the 7.6.0 milestone Jan 26, 2022
@baubakg baubakg changed the title Conflict beween config failure skips and listener foced exceptions Conflict beween config failure skips and listener forced exceptions Jan 31, 2022
@krmahadevan krmahadevan modified the milestones: 7.6.0, 7.7.0 May 18, 2022
@krmahadevan krmahadevan removed this from the 7.7.0 milestone Dec 6, 2022
@krmahadevan
Copy link
Member

@baubakg - I was not able to reproduce the error using 7.4.0. Please find attached a sample project for the same. Can you please confirm ?
github_2721.zip

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