Hello Cedric,
thank you for so fast response.
Yes, It was run without including any groups.
I have made new test. I have prepare next class:
public class SimpleNGTest {
//Before methods
@BeforeMethod(groups = {"A"})
public void beforeMethodA() {
System.out.println("Before method for group A");
}
@BeforeMethod(groups = {"B"})
public void beforeMethodB() {
System.out.println("Before method for group B");
}
// Tests
@Test(groups = {"A"})
public void testA() {
System.out.println("Test from group A");
}
@Test(groups = {"B"})
public void testB() {
System.out.println("Test from group B");
}
//after methods
@AfterMethod(groups = {"A"})
public void afterMethodA() {
System.out.println("After method for group A");
}
@AfterMethod(groups = {"B"})
public void afterMethodB() {
System.out.println("After method for group B");
}
}
I have run this test from Idea's plugin without including any groups,
just right click on this class and select "Run SimpleNGTest" and have
got next result into console:
Before method for group B
Before method for group A
Test from group A
After method for group B
After method for group A
Before method for group B
Before method for group A
Test from group B
After method for group B
After method for group A
Ok, next step I have tried to run tests with Maven. I have used
Surfire plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<disableXmlReport>true</disableXmlReport>
</configuration>
</plugin>
This means, that I don't specify groups for TestNG, and tests will be
run without including any groups. Am I right?
I have run test phase and I have got next in console:
Before method for group B
Before method for group A
Test from group A
After method for group B
After method for group A
Before method for group B
Before method for group A
Test from group B
After method for group B
After method for group A
It was the same result as for Idea plugin.
To be sure, I have made the same test for command line with using
testng.xml:
<!DOCTYPE suite SYSTEM "
http://testng.org/testng-1.0.dtd" >
<suite name="Suite1" verbose="1" >
<test name="OneClass">
<classes>
<class name="com.edg.earth.SimpleNGTest"/>
</classes>
</test>
</suite>
And I have got this result:
c:\JAVA>java -cp testng-5.8-jdk15.jar;./ -Dtestng.test.classpath="c:
\Java" org.testng.TestNG testng.xml
[Parser] Running:
C:\JAVA\testng.xml
Before method for group B
Before method for group A
Test from group A
After method for group B
After method for group A
Before method for group B
Before method for group A
Test from group B
After method for group B
After method for group A
===============================================
Suite1
Total tests run: 2, Failures: 0, Skips: 0
===============================================
It's the same result as I have before. And in my opinion, problem not
in TestNG and not in Idea, problem is in my understanding of TestNG
principles.
If I have started tests without <u>specifying groups</u>, I will get
result which I have got in previous experiments.
In my opinion, If I specify before method as belonged to group "A",
this method have to be executed only before tests from group "A" and
never else, independently from run with including groups or not. I
must ever have got next log:
Before method for group A
Test from group A
After method for group A
Before method for group B
Test from group B
After method for group B
But, as I can understand, when I don't specify executed groups, before
and after methods are executed independently from group specifying.
<br>
After I have modified my testng.xml and include groups A and B:
<!DOCTYPE suite SYSTEM "
http://testng.org/testng-1.0.dtd" >
<suite name="Main" verbose="1" >
<test name="Group A">
<groups>
<run>
<include name="A"/>
<include name="B"/>
</run>
</groups>
<classes>
<class name="com.edg.earth.SimpleNGTest"/>
</classes>
</test>
</suite>
But I have got the same result:
Before method for group B
Before method for group A
Test from group A
After method for group B
After method for group A
Before method for group B
Before method for group A
Test from group B
After method for group B
After method for group A
I have fix this problem the next way. I have wrote in testng.xml,
please, run two tests, first for group A, second for group B. You
could find it below:
<!DOCTYPE suite SYSTEM "
http://testng.org/testng-1.0.dtd" >
<suite name="Main" verbose="1" >
<test name="Group A">
<groups>
<run>
<include name="A"/>
</run>
</groups>
<classes>
<class name="com.edg.earth.SimpleNGTest"/>
</classes>
</test>
<test name="Group B">
<groups>
<run>
<include name="B"/>
</run>
</groups>
<classes>
<class name="com.edg.earth.SimpleNGTest"/>
</classes>
</test>
</suite>
In this case, I have got the next log:
c:\JAVA>java -cp testng-5.8-jdk15.jar;./ -Dtestng.test.classpath="c:
\Java" org.testng.TestNG testng.xml
[Parser] Running:
C:\JAVA\testng.xml
Before method for group A
Test from group A
After method for group A
Before method for group B
Test from group B
After method for group B
===============================================
Main
Total tests run: 2, Failures: 0, Skips: 0
===============================================
Yes! It's what I need!
I can use It for Maven or Ant test task for my project, because I
could specify necessary testng.xml, but in case of Idea one click run,
I have no vision, how to get what I need.
Sorry for so big mail, but I want to explain my problem fully.
If TestNG will execute before and after methods only for tests from
their groups independently from run including groups or not, it will
be very useful for my project. It could allow to write in a test,
"this methods will be executed before tests from necessary group and
never else". It could allow me to run different configuration of tests
but be sure, that wrong DB configuration never will be created before
tests, which need another one. It will be very useful to specify two
groups of tests, every might have self environment initialized in self
@BeforeTest method, and when I will run tests from both groups
simultaneously, I can be sure that first environment will be
initialized, tests from first groups will be executed, after second
environment will be initialized and tests from second groups will be
executed.
I have created briefly diagram of my suggestion (Picase web link).
http://lh6.ggpht.com/aleksey.didik/SNDFgsI3qpI/AAAAAAAAACo/NJV846acv-I/s720/TestFramework.jpg"
Wait for your response,
Best regard, Aleksey.
On 16 сент, 20:20, Cédric Beust ♔ <
cbe...@google.com> wrote:
> Hi Aleksey,
>
> It looks like this was run without including any groups. Could you try your
> example with TestNG from the command line and a testng.xml that includes
> group "1" and let us know if you see the same result?
>
> If you do, it's a bug in TestNG, if you don't, the problem is probably in
> the IDEA plug-in.
>
> --
> ***Cédric
> *