Reputation: 3728
I'm having some strange issues using TestNG with maven. I have too much code to post here, but I'll post a relevant example.
I have this for TestNG tests in my pom.xml:
....other pom stuff....
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.2</version>
<type>jar</type>
</dependency>
....other pom stuff....
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
....other pom stuff....
My testng.xml file looks like this:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="SOTest">
<test name="SOTest">
<classes>
<class name="SOTest"/>
</classes>
</test>
</suite>
And SOTest.java looks like this:
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
public class SOTest {
@BeforeSuite
public void setup() {
...DO SOME STUFF...
System.out.println("foo");
}
@BeforeTest
public void setupTest() {
...DO SOME STUFF...
System.out.println("bar");
}
@Test
public void test_good_subkey_pass() {
System.out.println("baz");
...DO SOME STUFF...
}
}
When running mvn test
, "foo" and "bar" are printed, but then it hangs and "baz" is never printed? Does anyone know what would prevent the methods annotated with @Test
from running?
UPDATE
There was another test after test_good_subkey_pass()
that had an infinite loop in it. Why would that stop the first test from being run? Note that the preserve-order
attribute is not set to false
.
Upvotes: 2
Views: 3137
Reputation: 114
You know the XML file defines the tests to be run, but TestNG does not run your tests in the order they exist in the class code. It appears your XML file specifies the order to run the class, but not the order to execute the methods. (Also, I know you can specify methods to include/exclude, but I'm not sure that even that defines the order they will run in. From my experience, tests have always run alphabetically.)
If another test had an infinite loop, that could explain why test_good_subkey_pass()
wasn't run. Try removing the other test cases to see if that resolves the problem (or use the @AfterSuite
or similar annotation to notify you of all test completion).
You may also just want to specify the method names in testng.xml
This is likely your best resource: http://testng.org/doc/documentation-main.html#testng-xml
Upvotes: 2