just want to follow up on the issues with @BeforeGroups/@AfterGroups.
For me it is not clear one thing:
where to put @xxxxGroups annotations as a group methods can be in different test classes (base class, a class with @xxxxGroups methods, ....)
To find an answer on my question I created an example:
package testng;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
@Test(groups = {"group-a"})
public class GroupTest {
@BeforeGroups(value = {"group-a"}, groups = {"group-a"})
public void init(){
System.out.println("Init GroupTest");
}
@AfterGroups(value = {"group-a"}, groups = {"group-a"})
public void destroy(){
System.out.println("Destroy GroupTest");
}
public void test1(){
System.out.println("test1");
}
public void test2(){
System.out.println("test2");
}
}
and here is the testng.xml
<?xml version="1.0"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Tests" verbose="2" parallel="false">
<test name="Group tests">
<groups>
<run>
<include name="group-a" />
</run>
</groups>
<packages>
<package name="testng"/>
</packages>
</test>
</suite>
[Parser] Running:
C:\Development\apps\eclipse-ws\sandbox\CEE2V3.0\src\testNG\testng\testng.xml
Init GroupTest
test1
test2
Destroy GroupTest
PASSED: test1
PASSED: test2
===============================================
Group tests
Tests run: 2, Failures: 0, Skips: 0
===============================================
===============================================
Tests
Total tests run: 2, Failures: 0, Skips: 0
In this case everything was as expected.
I want to have another test method in the 'group-a' but located in different class.
package testng;
import org.testng.annotations.Test;
@Test
public class GroupTest2 {
@Test(groups = {"group-a"})
public void test3(){
System.out.println("test3");
}
}
I was bit surprised with the output:
[Parser] Running:
C:\Development\apps\eclipse-ws\sandbox\CEE2V3.0\src\testNG\testng\testng.xml
Init GroupTest
test1
test2
test3
PASSED: test1
PASSED: test2
PASSED: test3
===============================================
Group tests
Tests run: 3, Failures: 0, Skips: 0
===============================================
===============================================
Tests
Total tests run: 3, Failures: 0, Skips: 0
===============================================
Looks like @AfterGroups annotated method in GroupTest class has not been called.
Is that expected behavior? Why is not called?
What happens if @AfterGroups method is also defined in GroupTest2 (I'll keep one in GroupTest).
Here is the output:
[Parser] Running:
C:\Development\apps\eclipse-ws\sandbox\CEE2V3.0\src\testNG\testng\testng.xml
Init GroupTest
test1
test2
test3
[b]Destroy GroupTest2[/b]
PASSED: test1
PASSED: test2
PASSED: test3
===============================================
Group tests
Tests run: 3, Failures: 0, Skips: 0
===============================================
===============================================
Tests
Total tests run: 3, Failures: 0, Skips: 0
===============================================
Hm, now the @AfterGroups method from GroupTest2 has been called....
So it looks like @BeforeGroups/@AfterGroups method is called from the test class from where testng executes first/last test method. If there is no such method nothing is executed.
I couldn't find any documentation which would help me in above cases for @xxxxxGroups. Maybe I cannot find it....
Comments are welcome.
Andrej
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=50238&messageID=101612#101612