Just do it!


How to use the testng with maven, adding dependecy to pom.xml

Posted in IT, maven by admin on the July 26th, 2012

To run your tests created with TestNG, Just create a file called pom.xml and add the following code:
This is tested and it works (I removed parts of dependecies from my pom.xml, but it should still work).

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>YOUR.GROUP.ID</groupId>
<artifactId>YOUR.ARTIFACT.ID</artifactId>
<packaging>jar</packaging>
<version>YOUR.VERSION.NUMBER</version>
<name>YOUR.PROJECT.NAME</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
<!--testSourceDirectory>OPTIONAL-YOUR_TESTS_PATH</testSourceDirectory-->
</build>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>5.10</version>
<classifier>jdk15</classifier>
<scope>test</scope>
</dependency>
</dependencies>
</project>

Just replace the “YOUR.*” with your specific values and you’re done.
All you have to do is to place this pom.xml file in the root of the test project and run “mvn test”.
By default, the tests should be located in: ./src/test/java/ folder relative to the project root.

Leave a Reply

You must be logged in to post a comment.