I see a problem in my testNG tests, the test is as follows.

```
public class testNG {

    @BeforeGroups(groups = {"smoketests", "functionaltests"})
    public void before() {
        System.out.println("Before Groups");
    }

    @Test(groups = {"smoketests", "functionaltests"})
    public void test() {
        System.out.println("Test");
    }

    @AfterGroups(groups = {"smoketests", "functionaltests"})
    public void after() {
        System.out.println("After Groups");
    }

```

}

When I run the tests from testNG command line by 

java -cp :libs/\* org.testng.TestNG -testjar libs/testNGLib.jar -groups smoketests

(Assume that the test jar is in some libs folder)

The output I get is as follows

```
Before Groups
Before Groups
Test
After Groups

```

I am not sure why the BeforeGroups is called twice even though I am only interested in running the test that's part of the smoketests group.

The problem doesn't happen if I only have smoketests group in the @Test directive, but I still don't understand the issue with @BeforeGroups with multiple groups in place.