Prerequisite requirement:
- Get a copy of TestNG from this site.Please note that I am not using the Eclipse plugin. The moment of this writingis 5.12.1
- Get the ant from apache’s site.
- Get the JDK from Sun’s site.
- Add a new environment variable called JAVA_HOME under the System Variable group. Set the path to the JDK installationdirectory. Without this the compiler will complain that tools.jar not foundduring the Ant process.
- Add the ant’s bin directory and jdk’sbin directory into Path environment variable under the System Variable group.
- Create a JAVA project using Eclipse.
- Add the testng-<version>.jar intobuild path and update all necessary info of the jar file (eg. SourceAttachment, JavaDoc, library location) for easier debugging purpose.
- Create the source code below under thatsrc directory and name it as SimpleTest.java. The code is actually copy fromTestNG’s site.
- Create the Ant file using code below:
- There are a couple of thing to take note here:
- the Ant must be told that where the location of the testng<version>.jarfile and where are the binary file in pathelement location.
- the destdir in javac indicate where the output of the binary class file shouldlocate after the compilation.
- the correct location of the binary class must be set in classfileset otherwisean error complain that the build.xml not found.
- After this, the testng-output directory will be generated. Notice that thetestng-results.xml is created automatically for generating the testng-xsltreport purpose.
package package1; import org.testng.annotations.*; public class SimpleTest { @BeforeClass public void setUp() { // code thatwill be invoked when this test is instantiated } @Test(groups = { "fast" }) public void aFastTest() { System.out.println("Fast test"); } @Test(groups = { "slow" }) public void aSlowTest() { System.out.println("Slow test"); } }
No comments:
Post a Comment