Anto
Anto

Reputation: 125

TestNG @BeforeMethod onlyForGroups option removed

I was looking for some way to have some @beforeMethod logic executing only for a group of java unit tests (using TestNG ). I found on TestNG documentation:

onlyForGroups: Only for @BeforeMethod and @AfterMethod. If specified, then this setup/teardown method will only be invoked if the corresponding test method belongs to one of the listed groups.

Which seems to be what I'm looking for.

But when I try to use it, it's not implemented in @BeforeMethod and @AfterMethod annotations. I couldn't find find any information on the web about it missing.

Maven dependency :

         <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.14.2</version>
            <scope>test</scope>
        </dependency>

Thanks for the help

Upvotes: 1

Views: 414

Answers (2)

jcompetence
jcompetence

Reputation: 8413

Notice the version of TestNG used in the dependency.

<dependencies>
        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>7.4.0</version>
            <scope>test</scope>
        </dependency>
</dependencies>

import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class TestNgBeforeMethodAnnotation {

    @BeforeMethod(onlyForGroups = {"Group1"}, groups = {"Group1"})
    public void setupForGroup1()
    {
        System.out.println("Before Method for Group 1 called");
    }

    @Test(groups = {"Group1"})
    public void testCaseInGroup1()
    {
        System.out.println("testCaseInGroup1");
    }

}

Upvotes: 0

Ori Marko
Ori Marko

Reputation: 58882

Upgrade you version, as you see in Changes, it was added after 6.14.3 version

Fixed: GITHUB-549 and GITHUB-780: Introduce onlyForGroups attribute for @BeforeMethod and @AfterMethod (Sergei Tachenov)

Upvotes: 1

Related Questions