Showing posts with label Testing. Show all posts
Showing posts with label Testing. Show all posts

Sunday, 1 February 2015

HOW TO USE TESTNG FRAMEWORK - SAMPLES-I

Just like Junit, TestNG provides very good testing strategies.

This post gives an overview of TestNG - a sample test case.

To you TestNG framework in your project you must use TestNG.jar

Ways To Download:

Official Download Link:  TestNG.jar

or

use git clone
git clone git://github.com/cbeust/testng.git  
or

If your using eclipse IDE, you can install TestNG as an eclipse plugin:
Read More...

After downloading TestNG jar file - add that jar to the project build path:

Now you are ready to use TestNG framework.

TestNG test cases  uses some important annotations:


All annotations are placed in the package:

org.testng.annotations.*;

@Test 

To write a test case - use @Test annotation.

Example:

package examples.testng;

import org.testng.annotations.Test;

public class MyFirstTest {

//First Test Case
@Test
public void validUser() {
// write your validation logic
System.out.println("Checking authorization");
}

//Second Test Case
@Test
public void checkBalance() {
// write a business logic to check the balance
System.out.println("Must check balance - before transactions");
}
} 


 How to run it?

It is very easy to run a test case in TestNG if your are using an IDE like eclipse

Right Click on Test Case Class->select "Run as"  -> TestNG test


More Concepts on TestNG ..coming soon

HOW TO INSTALL TESTNG FRAMEWORK AS A PLUGIN IN ECLIPSE

Testng framework is available on Eclipse IDE as a plugin.

Steps to Install:

Step1:

go to "Help" Menu -> click on "install new software"



Step2:

Click Add.... button 

This opens a pop up - Add Repository

For Name Field - enter any name for the installation location

Location Filed:

In location field enter url as per eclipse IDE version


Step3:

After adding respository location

select the checkbox "TestNG"



Step4:

Click next -  be patient it takes some time - then


click - "I accept the terms ...."



Step5:

Click install- you can also choose to run in background

- now this starts installation



NOTE:

To install any new plugin you follow this way of adding the respective software location as a repository.

Thank You
Hope you like it...