This is
the process I used to setup TestNG for my automation framework:
Step1: Download latest JDK
from here.
Step2: Set JAVA_HOME
environment variable
- You can set
JAVA_Home either by using following command prompt:
C:\Program Files\(path to JDK folder)
- Or you can do it thru environment variables like so:
i. Find out where Java is installed. If you didn't change the path
during installation, it will be something like this:
C:\Program Files\Java\jdk(your
version)
ii. In Windows 7 right click My
Computer and select Properties >Advanced.
In Windows 8 go to Control Panel > System > Advanced System Settings.
In Windows 8 go to Control Panel > System > Advanced System Settings.
In Windows
10 Type 'advanced system settings' in the search box (beside the Windows
start button), click 'View advanced system settings'. The images below are for Win10.
iii. Click the Environment
Variables button.
iv. Under System
Variables, click New.
v. In the Variable Name field,
enter:
JAVA_HOME
vi. In the Variable Value field, enter your
JDK installation path.
vii. If the path contains
spaces, use the shortened path name, for example -
C:\Progra~1\Java\(path to JDK)
Step3: Update PATH like so:
- Either using the following command prompt:
%PATH%;%JAVA_HOME%\bin
- Or by clicking on PATH variable and updating with (%JAVA_HOME%\bin) like so:
i. Go to environment variables and click on the PATH variable under System settings
iii. Add %JAVA_HOME%\bin
iv. Hit 'OK'
Step4: Download TestNG per instruction on this page.
Step5: Set TESTNG_HOME in
environment variables. The process is same like setting JAVA_HOME above. The
location has to point to the
base directory location, where TestNG jar is stored on your machine.
Step6: Set CLASSPATH for
TestNG jar like so:
- Either using the following command prompt:
%CLASSPATH%;%TESTNG_HOME%\testng-(jar version).jar
- Or using the same process explained above to set PATH variable for JAVA, except we will add the variable to CLASSPATH like so:
%TESTNG_HOME%\testng-(jar version).jar
Step7: Once the setup is complete, we can verify
TestNG setup like so:
1. Create a TestNG_Workspace
2. Create a java class file named
‘verifyTestNG’ like so:
1 2 3 4 5 6 7 8 9 10 | import org.testng.annotations.Test; import static org.testng.Assert.assertEquals; public class TestNGSimpleTest { @Test public void testAdd01() { String str = "TestNG is working fine"; assertEquals("TestNG is working fine", str); } } |
3. TestNG can be invoked by using
any of the following 3 methods:
a. testng.xml
b. ANT
c. From command prompt
This is sample testng.xml file to invoke TestNG:
1 2 3 4 5 6 7 8 9 10 11 | <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name="testSuite1"> <test name="testName1"> <classes> <class name="testAdd01"/> <class name="testNGSampleTest02"/> </classes> </test> </suite> |
To see ANT build process, click here.
No comments:
Post a Comment