Simple Example to Execute TestNG tests
This section will begin with a simple example which will illustrate the basic concepts involved in testing with TestNG.
1. By convention we will create HelloWorld class and we will invoke the TestNG through command line. Create a test folder folder in C drive Ex: C:\TestNG-Examples.
public class HelloWorld{
@Test
public void HelloWorld()
System.out.println("Hello World");
}
}
2. Save the above code with HelloWorld.java in the above location.
<suite name="HelloWorldTestSuite">
<test name="HelloWorld">
<classes>
<class name="HelloWorld"> </class>
</classes>
</test>
</suite>
public class HelloWorld{
@Test
public void HelloWorld()
System.out.println("Hello World");
}
}
2. Save the above code with HelloWorld.java in the above location.
3. Compile the above code. Open command prompt, and compile the code
C:\TestNG-Examples\javac HelloWorld.java
4. Now you need to create a xml file to run the above program in TestNG. Copy the below xml scripts and create a HelloWorldTestng.xml file in the same location i.e., C:\TestNG-Examples\testng1.xml
<suite name="HelloWorldTestSuite">
<test name="HelloWorld">
<classes>
<class name="HelloWorld"> </class>
</classes>
</test>
</suite>
5. Now to invoke TestNG, use the following command
java org.testng.TestNG HelloWorldTestng.xml
6. Your output should look like the following in the command prompt
7. If you look at the same directory where your tests are there, TestNG has created one more folder called "test-output". If you want to see your out put in a HTML format, go and open index.html
Alternatively, you can open the report from the command prompt by using the following command
start test-output\index.html
Useful!
ReplyDeleteThank you...
ReplyDelete