What is the scope of the @BeforeGroups annotation, is it "class" (runs before all test methods in a class which belong to the group) or "suite" (runs before all test methods in the suite which belong to the group) ?
public class FactoryExample {
@BeforeGroups(groups = { "tabletests" })
public void init() {
Reporter.log("init()");
}
@Test(groups = { "tabletests" })
public void testMe() {
Reporter.log("testMe()");
}
}
thankyou,
Chris
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=42150&messageID=84327#84327
I think the answer is: test level. As you know a suite is composed up from tests. A before/after
group method is invoked around the tests methods making up a group (from the classes included in a
test). Does this answer your question?
./alex
--
.w( the_mindstorm )p.
TestNG co-founder
------------------------
@Test
public class BaseTest {
@BeforeGroups(groups = { "oracle" }, alwaysRun = true)
public void start() throws Exception {
....
something
....
// Test startup.
Connection connection = cruncher.createConnection();
connection.close();
}
@AfterGroups(groups = { "oracle" }, alwaysRun = true)
public void end() throws Exception {
Main.stop();
}
}
------------------------
public class UndoTest {
public void do1() {
System.out.println("do1");
}
@Test(groups = { "oracle" })
public void test() {
Helper helper = new Helper();
List<Entry> remainingEntries = helper.undo(true);
Assert.assertEquals(2, remainingEntries.size());
for (Entry entry : remainingEntries) {
System.out.println(entry.getMethodName());
}
}
}
------------------------
Could you pls explain how this Group/Suite thing works? The documentation and examples in the 5.1 distribution are out of date, referring to @Configuration annotations.
Alex, I didn't understand your explanation of the "Test level" in your previous reply. I am executing the appropriate group (from Eclipse), so why don't the Before/AfterGroups methods get called?
Thanks,
Ashwin (www.JavaForU.com)
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=42150&messageID=85681#85681
<suite name="Suite" verbose="5" >
<test name="All">
<groups>
<run>
<include name="oracle" />
</run>
</groups>
<packages>
<package name="test.*" />
</packages>
</test>
</suite>
Ashwin.
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=42150&messageID=85683#85683
./alex
--
.w( the_mindstorm )p.
TestNG co-founder
EclipseTestNG Creator
However, why does this get invoked even if the Suite I'm executing in the testng.xml says "oracle", while the @BeforeSuite says "func"? What is the significance of the "groups" parameter in the Before/AfterSuite annotation?
It would help users a lot if the docs described the possible combinations of all these tags and their meanings. This is one of the best features of TestNG, compared to Junit4.
Ashwin.
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=42150&messageID=85694#85694
When I changed the BeforeGroups to @BeforeSuite(groups = { "func" }, alwaysRun = true), it started getting invoked.
However, why does this get invoked even if the Suite I'm executing in the testng.xml says "oracle", while the @BeforeSuite says "func"?
Hi Ashwin!
Unfortunately I cannot easily reproduce the problem you are
mentioning. If you can send me offline a test that reproduce the
problem than this would be really great.
> It would help users a lot if the docs described the possible combinations of all these tags and their meanings. This is one of the best features of TestNG, compared to Junit4.
>
Please let us know how would you improve the documentation and we will
be very happy to apply the changes you are suggesting.
./alex
--
.w( the_mindstorm )p.
TestNG co-founder
EclipseTestNG Creator
> Ashwin.
The code is really crude, mind you; only to reproduce the issue and that's not how I normally write my programs :-)
Thanks,
Ashwin.
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=42150&messageID=85724#85724
./alex
--
.w( the_mindstorm )p.
TestNG co-founder
EclipseTestNG Creator
PS: if you check TestNG site http://testng.org you will notice on the
home page (top right corner) my private email.
On 9/10/06, Ashwin Jayaprakash <testng...@opensymphony.com> wrote:
------------------
package temp;
import org.testng.Assert;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.AfterGroups;
/*
* Author: Ashwin Jayaprakash Date: Sep 10, 2006 Time: 9:33:34 PM
*/
public class BaseTestCase1 {
public static final String OLD_VAL = "OLD";
public static final String NEW_VAL = "New!!!";
public static String CHECK = OLD_VAL;
@BeforeGroups(groups = { "oracle" }, alwaysRun = true)
public void start() throws Exception {
System.out.println("start");
CHECK = NEW_VAL;
}
@AfterGroups(groups = { "oracle" }, alwaysRun = true)
public void end() throws Exception {
System.out.println("end");
}
}
------------------
Ashwin.
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=42150&messageID=85839#85839
Try this (the older attachment was messed up)
-------------------
@Test(groups = { "func", "oracle.sliding" })
public class SimpleTestNG {
protected boolean called = false;
@BeforeGroups
public void init() throws Exception {
called = true;
System.out.println("init");
}
@Test
protected void testSlidingWindow() throws Exception {
Assert.assertEquals(called, true);
}
@AfterGroups
public void discard() {
System.out.println("discard");
}
}
-------------------
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite" verbose="5" >
<test name="All">
<groups>
<run>
<include name=".*" />
</run>
</groups>
<packages>
<package name="temp.*" />
</packages>
</test>
</suite>
-------------------
Ashwin.
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=42150&messageID=86056#86056
Even tried this one with method level Annos and a static variable:
public class SimpleTestNG {
protected static boolean called = false;
@BeforeGroups(groups = { "func", "oracle.sliding" })
public void init() throws Exception {
called = true;
System.out.println("init");
}
@Test(groups = { "func", "oracle.sliding" })
protected void testSlidingWindow() throws Exception {
Assert.assertEquals(called, true);
}
@AfterGroups(groups = { "func", "oracle.sliding" })
public void discard() {
System.out.println("discard");
}
}
Look at the logs attached. Is there some secret chant, that I'm not uttering while the test runs? Aaarrggh...
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=42150&messageID=86067#86067
But Cedric/Alex, this setting seems confusing. Why keep both a groups and a value tag? They seem to be redundant.
Ashwin.
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=42150&messageID=86308#86308
Got it - I referred this post and realised that the "value" attribute was missing!
But Cedric/Alex, this setting seems confusing. Why keep both a groups and a value tag? They seem to be redundant.
If the BeforeGroups says @BeforeGroups(groups = { "grp-a", "grp-b" }), will it get invoked multiple times?
Also, since TestNG does not enforce static/instance level methods, how do the instances get created for the example above? Will the class get instantiated twice - once for grp-a and then again for grp-b? And will the method get invoked twice?
And, what bearing does the Class-level groups have on Before/AfterGroups annos? Don't they become members automatically? You said in your comment above that @Before/After annos must have explicit groups defined.
I feel such scenarios/behaviours need to be documented, now that TestNG has reached version 5.1. Otherwise, people will simply turn to JUnit4, which is straight-forward even though it does not provide such "advanced" features.
Anyway, thanks and "Nice work!".
Ashwin.
---------------------------------------------------------------------
Posted via Jive Forums
http://forums.opensymphony.com/thread.jspa?threadID=42150&messageID=86325#86325