Reading:  

Working with TestNG - Starters Guide


Setting up and testing the Environment

TestNG framework is for Java so make sure that JDK installed and also eclipse because we are using eclipse to work with TestNG.

Install Java Software Development Kit (SDK) from below link http://www.oracle.com/technetwork/java/javase/downloads/index.html

To set environment for Java:

Set the JAVA_HOME environment variable to the base directory location where Java is installed.

For windows to set the environment variable JAVA_HOME: C:\ProgramFiles\Java\jdk1.8.0_25

For Linux Export JAVA_HOME=/usr/local/java-current

For MacExport JAVA_HOME=/Library/Java/Home

To add Java compiler location to System Path:

For windows add the path C:\Program Files\Java\jdk1.8.0_25\bin at end of system variable Path by putting semicolon at the end. Do not delete/edit old path.

For Linux Export PATH=$PATH:$JAVA_HOME/bin/

For Mac not required

To verify Java Installation using the command javac:

 Go to command prompt and type the command javac you should get this out if java is successfully installed.

Test Java command

Here in eclipse we are enabling TestNG. We can also execute JUnit test outside the eclipse that is discussed in future topics.

Steps to enable TestNG in eclipse:

Note: TestNG is not built in eclipse

In order to install TestNG follow below steps:

  1. Go to help in eclipse, click on Install New software



  2. To start installation process, click the Add button as shown:



  3. Now enter the name as TestNG and in the "Location", type the URL: http://beust.com/eclipse, click ok button:



  4. Click “Select All”, then check the “TestNG” then click “Next”:




  5. Click 'Next' to begins the installation process:



  6. Here click the radio button "I accept the terms of the license agreement" and then click Finish button.




  7. Now the installation process starts ,Wait for the installation to finish



  8. We will get Security warning dialog box, click OK




  9. Software Updates dialog box will pop-up to restarteclipse, click "Yes".

 

Verify the setup of TestNG

To verify the setup of TestNG:

  • Creating a java class file named classA at C:\>Users\testng\workspace.
    package TestNG;
    import org.TestNG.annotations.Test;
    import staticorg.TestNG.Assert;
    
    public class classA {@Test
    	publicvoid method1() {
    		System.out.println("inside the method1");
    		String msg = "Welcome to TestNG";
    		assertEquals("Welcome to TestNG", msg);
    	}
    }
  • Run the above program by clicking on Run button of eclipse.

    Ouput


 

 

Description

This tutorial is focused on getting you started on TestNG, the testing framework inspired from JUnit and NUnit. Here is a quick table of contents

  1. What is TestNG?
  2. Environment Set-up
  3. Writing Tests
  4. Basic Annotations
  5. Execution Procedure
  6. Executing Tests
  7. Suite Test
  8. Ignore Test
  9. Group Test
  10. Exception Test
  11. Dependency Test
  12. Parametrized Test
  13. JUnit Tests
  14. Test Reports
  15. Running tests without Eclipse
  16. Plugin with ANT

 

 



Environment

A computer capable of running Java. IntelliJ Community IDE is also required for this course.

Prerequisites

Good knowledge of Java programming language and eclipse is essential.

Audience

Students looking to get started with TestNG

Learning Objectives

This tutorial will get you started with TestNG.

Author: Subject Coach
Added on: 12th Mar 2015

You must be logged in as Student to ask a Question.

None just yet!