Just do it!


Specifying suite in maven for testng

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

Using Suite XML Files

Another alternative is to use TestNG suite XML files. This allows flexible configuration of the tests to be run. These files are created in the normal way, and then added to the Surefire Plugin configuration:
In the previously created pom.xml file, you can replace the plugin section with this one, and now instead of running all the tests, you can specify which of them should be run using a testng suite file (in this case called testng.xml).

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>

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.