Skip to content

Before/After methods are not running when groups "include" in suite #1574

Open
@chetand24

Description

@chetand24

TestNG Version : 6.12.0, 6.11.0

Note: only the latest version is supported

Expected behavior

The Before and After methods should run when "include" tag is present in the testng suite

Actual behavior

The Before and After methods are not running when "include" tag present in the testng suite. But is working fine when "exclude" is present

Is the issue reproductible 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

The test class:

public class AnotherTest {

    @BeforeSuite
    public void setupSuite(){
        System.out.println("Before Suite Setup ...... ");
    }

    @BeforeTest
    public void setUpTest() throws Exception {
        System.out.println("Before Test Setup ...... ");
    }

    @BeforeMethod
    public void setUpMethod() throws URISyntaxException {
        System.out.println("Before Method Setup ...... ");
    }

    @AfterMethod
    public void tearDownMethod(){
        System.out.println("After Method Setup ...... ");
    }

    @AfterTest
    public void tearDownSuite() throws Exception {
        System.out.println("After test Setup ...... ");
    }

    @Test(groups = {"sometest"})
    public void someTest(){
        System.out.println("Some test ...... ");
    }

    @Test(groups = {"anothertest"})
    public void anothertest(){
        System.out.println("Another test ...... ");
    }
}

Example XML Suite

<suite name="Mobile Test" verbose="10">
    <test name="Some Tests">
        <groups>
            <run>
                <!--<exclude name="sometest"/>-->
                <include name="sometest"/>
            </run>
        </groups>
        <classes>
            <class name="com.practice.AnotherTest"/>
        </classes>
    </test>
</suite>

Output when included the group:

...
... TestNG 6.11 by Cédric Beust ([email protected])
...
Some test ...... 
===== Invoked methods
    AnotherTest.someTest()[pri:0, instance:com.practice.AnotherTest@7cf10a6f] 2096171631
=====
===============================================
Mobile Automated Test for Engage Android
Total tests run: 1, Failures: 0, Skips: 0
===============================================

Output when excluded the group:

...
... TestNG 6.11 by Cédric Beust ([email protected])
...
Before Suite Setup ...... 
Before Test Setup ...... 
Before Method Setup ...... 
Another test ...... 
After Method Setup ...... 
After test Setup ...... 
===== Invoked methods
  AnotherTest.setupSuite()[pri:0, instance:com.practice.AnotherTest@5ba23b66] 1537358694
  AnotherTest.setUpTest()[pri:0, instance:com.practice.AnotherTest@5ba23b66] 1537358694
  AnotherTest.setUpMethod()[pri:0, instance:com.practice.AnotherTest@5ba23b66] 1537358694
    AnotherTest.anothertest()[pri:0, instance:com.practice.AnotherTest@5ba23b66] 1537358694
  AnotherTest.tearDownMethod()[pri:0, instance:com.practice.AnotherTest@5ba23b66] 1537358694
  AnotherTest.tearDownSuite()[pri:0, instance:com.practice.AnotherTest@5ba23b66] 1537358694
=====

===============================================
Mobile Automated Test for Engage Android
Total tests run: 1, Failures: 0, Skips: 0
===============================================

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions