Sunday, November 3, 2013

Downloading TestNG



Before we can download and start using TestNG, there are certain prerequisites we need. So, let's go ahead with the prerequisites first.

Prerequisites

Before you start using TestNG please make sure that Java JDK5 or above is installed on your system. Also make sure that JDK is set in the system path. In case JDK is not available on your system, you can download it from the following link:
TestNG can be downloaded, installed, and run in multiple ways as follows:
·         Using command line
·         As an Eclipse plugin
·         As an IntelliJ IDEA plugin
·         Using ANT
·         Using Maven
In case you just want to download the TestNG JAR, you can get it from the following URL:


Installing TestNG onto Eclipse



Before we go forward with installing the TestNG plugin onto Eclipse, please make sure you have Eclipse installed on your system. You can get the latest version of eclipse fromhttp://www.eclipse.org/downloads/. At the time of writing this book, I am using Eclipse JEE Juno-SR1 version.


Time for action – installing TestNG onto Eclipse



Let's start with the installation process of TestNG onto Eclipse:
1.      Open your Eclipse application.
2.      Go to Help | Install New Software.
      
3.      Click on the Add… button next to the Work with text box.
4.      Enter TestNG site into the Name box and enter URL http://beust.com/eclipse into the Location box. Once done, click on the OK button.
5.      On clicking OK, TestNG update site will get added to Eclipse. The available software window will show the tools available to download under the TestNG site.
6.      Select TestNG and click on Next.
7.      Eclipse will calculate the software requirements to download the selected TestNG plugin and will show the Install Details screen. Click on Next on the details screen.
8.      Accept the License Information and click on Finish. This will start the download and installation of the TestNG plugin onto Eclipse.
9.      In case you get the following warning window, click on the OK button.
10.  Once the installation is complete, Eclipse will prompt you to restart it. Click on Yes on the window prompt.
11.  Once Eclipse is restarted, verify the TestNG plugin installation by going to Window | Preferences. You will see a TestNG section under the preferences window.


Features of TestNG


Now that you are at least a little familiarized with TestNG, let's go forward and discover more about the features offered by TestNG. The following are a few of the most important features:
·         Multiple Before and After annotation options: TestNG provides multiple kinds of Before/After annotations for support of different setup and cleanup options.
·         XML-based test configuration and test suite definition: Test suites in TestNG are configured mainly using XML files. An XML file can be used to create suites using classes, test methods, and packages, as well as by using TestNG groups. This file is also used to pass parameters to test methods or classes.
·         Dependent methods: This is one of the major features of TestNG where you can tell TestNG to execute a dependent test method to run after a given test method. You can also configure whether the dependent test method has to be executed or not in case the earlier test method fails.
·         Groups/group of groups: Using this feature you can assign certain test methods into particular named groups and tell TestNG to include or exclude a particular group in a test.
·         Dependent groups: Like dependent methods, this feature allows test methods belonging to one group being dependent upon another group.
·         Parameterization of test methods: This feature helps users to pass parameter values through an XML configuration file to the test methods, which can then be used inside the tests.
·         Data-driven testing: TestNG allows users to do data-driven testing of test methods using this feature. The same test method gets executed multiple times based on the data.
·         Multithreaded execution: This allows execution of test cases in a multithreaded environment. This feature can be used for parallel test execution to reduce execution time or to test a multithreaded test scenario.
·         Better reporting: TestNG internally generates an XML and HTML report by default for its test execution. You can also add custom reports to the framework if required.

·         Open API: TestNG provides easy extension of API, this helps in adding custom extensions or plugins to the framework depending upon the requirement.
What is TestNG ?

TestNG, where NG stands for "next generation" is a test automation framework inspired by JUnit (in Java) and NUnit (in C#). It can be used for unit, functional, integration, and end-to-end testing. TestNG has gained a lot of popularity within a short time and is one of the most widely used testing frameworks among Java developers. It mainly uses Java annotations to configure and write test methods.
TestNG was developed by Cedric Beust. He developed it to overcome a deficiency in JUnit. A few of the features that TestNG has over JUnit 4 are:
·         Extra Before and After annotations such as Before/After Suite and Before/After Group
·         Dependency test
·         Grouping of test methods
·         Multithreaded execution
·         In-built reporting framework
So, let's get familiarized with TestNG. As I mentioned earlier, TestNG is a testing framework. It is written in Java and can be used with Java as well as with Java-related languages such as Groovy. In TestNG, suites and tests are configured or described mainly through XML files. By default, the name of the file is testng.xml, but we can give it any other name if we want to.
TestNG allows users to do test configuration through XML files and allows them to include (or exclude) respective packages, classes, and methods in their test suite. It also allows users to group test methods into particular named groups and to include or exclude them as part of the test execution.
Parameterization of test methods is very easy using TestNG and it also provides an easy method of creating data-driven tests.

TestNG exposes its API which makes it easy to add custom functionalities or extensions, if required.