Annotation Framework

In this section, we will discuss on the Annotation framework in TestNG. TestNG is a framework which accept the input Test data from CSV file or XLS file and manipulate these with automation test script and generate report and logs which has better visualization and need to share to client or tracking the progress.

Annotation Framework

TestNG XML file:

This file is core of the TestNG Framework. This files helps us to configure how we will group our test case, how to run the test parallelly etc. and execute this from command prompt or ant script.

In Java, when you want to write a test case you need to write different class to create multiple Test case. But in TestNG, in one single class you can define multiple Testcase and configure this based on the requirement by using this Testng.xml file.

When you run a TestNG Testcase in Eclipse, it will generate the HTML report by default from which you can see the Passed and failed Testcase with details. This HTML report also create XML file which can be used to run through command prompt. If you are beginner to TestNG then please go through TestNG basic.

Let’s discuss below in detail.

<?xml version="1.0" encoding="UTF-8"?>
<suite name="My First Test Suite" guice-stage="DEVELOPMENT" parallel="classes">
	<test thread-count="5" name="Test1" verbose="2">
			<class name="com.testng.xml.TestNGXMLTest" />

Components of XML File

Above example is very simple. Let’s understand each component of the xml file.

  1. Suite : This defines one xml file which name as testing.xml. It has several attribute to configure.
  2. Name : It signifies the name of the Test suite. This is mandatory for suite tag.
  3. Verbose: It signifies the verbosity of the test. This is generally the level of verbose of the Test. The value of the verbose is starting from 1 to 10. Verbose 10 will display more result in console panel where Verbose 1 will display less details.
  4. Parallel: Through the Parallel attribute you can configure the test to run parallel. It has 4 parameter
    • Test : TestNG will run @Test methods in tag parallel in the same thread. But each tag will be in separate thread;
    • Method : TestNG will run each method in a single thread. This optimize the time significantly because more tests are run in parallel.
    • Class: TestNG will execute the test classes in parallel. Each test classes which are part of the execution will be executed in separate thread.
  5. Thread-count: It limits the number of threads which will be running parallel. This will be enabled if the test is enabled for Parallel mode otherwise it will be ignored
  6. Annotation: This is the annotation you use in your test.
  7. Time-out: This signifies the duration of the test run. If it is not executed till the time mentioned in time-out then test will be failed and marked as Failed in report. 

Now we are clear on the testng.xml file and Annotation framework in TestNG.

Leave a Reply

Your email address will not be published. Required fields are marked *