@BeforeGroups/@AfterGroups oddities

11 views
Skip to first unread message

Mark Derricutt

unread,
Nov 9, 2006, 10:20:18 PM11/9/06
to testng...@googlegroups.com
I was just helping out a coworker with a testng issue he was having with @BeforeGroups and it turns out he was missing the values="" parameter  so his method was never being run.

I notice theres no mention of the values parameter in the documentation for @ BeforeXXX/@AfterXXX (its in the javadoc thou).

Would it be acceptable to:

a) default the values parameter to the value of groups if its not defined or
b) through an error/warning if the values paramter is not defined

Mark



--
http://www.talios.com
http://www.flickr.com/photos/talios

akovcic

unread,
Nov 14, 2006, 8:27:29 AM11/14/06
to testng...@googlegroups.com
Hi,

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

Cédric Beust ♔

unread,
Nov 14, 2006, 11:46:33 AM11/14/06
to testng...@googlegroups.com
Hi Andrej,

I think you're are hitting an undefined behavior in TestNG, but I'll have to double check.

I'll get back to you.

--
Cedric
--
Cédric
Reply all
Reply to author
Forward
0 new messages