Reputation: 11
I have Maven Project and all the configuration is correct, recently i configured the project with GIT and Jenkins,Created Jenkin job.
Earlier i was able to run the complete project by Right click on project and Run **--> **Run --> Maven test and test execution use to start but now its not throwing any error but not launching the browser for execution.
But if i run the java file [Single test case] separately using TestNG its working as expected[launching the browser and starts the execution]
As i have configured with Jenkins i cannot run every test case separately. I will have to run the project with Maven test
I have tried the possible solutions :
Please find the code snippet that i have used in pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
</plugin>
</plugins>
</build>
Thanks in advance for all the suggestions :)
Upvotes: 0
Views: 1648
Reputation: 60
If your testng.xml or xml file with test cases is in root directory of project you can try below command.
This will trigger all test cases present in testng.xml
mvn clean test -Dsurefire.suiteXmlFiles=testng.xml
This will execute single test case
mvn clean test -Dtest=className
Please not that, you need to have surefire plugin into the pom.xml.
Upvotes: 0
Reputation: 4035
To trace cause, You may go through by below steps. And you will be found where is actual cause and it gets stuck.
1. Create Simple @Test with Console output:
public class NewTest {
@Test
public void f() {
System.out.println("Hello World");
}
}
2. Create TestNG.XML at root location of the project to execute above class:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test thread-count="5" name="Test">
<classes>
<class name="packageName.NewTest"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
3. Run and Check TESTNG.XML output
4. Run and Check output from POM.XML
POM.XML:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
Upvotes: 1
Reputation: 799
<test name="sample-Test" preserve-order="true" verbose="2">
<packages>
<package name="org.sample.something.*"/>
</packages>
</test>
2.1 Update your surefire plugin configuration to make it:
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
2.2 OR (more flexible as you can create different profiles pointing to different xml to run different test suites separately) Create a maven profile that will point to your testNG xml
<profiles>
<profile>
<id>selenium-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
mvn clean test -U -Pselenium-tests
OR mvn clean test
Upvotes: 0