SlideShare a Scribd company logo
TestNG is a testing framework developed in the lines of JUnit and
NUnit, however it introduces some new functionalities that make it
more powerful and easier to use.
TestNG is designed to cover all categories of tests − unit, functional,
end-to-end, integration, etc., and it requires JDK 5 or higher.
What is TestNG?
 TestNG is an open source automated testing
framework; where NG meansNext Generation. TestNG
is similar to JUnit (especially JUnit 4), but it is not a
JUnit extension. It is inspired by JUnit. It is designed to
be better than JUnit, especially when testing
integrated classes. The creator of TestNG is Cedric
Beust.
TestNG Features
 Supports annotations.
 TestNG uses more Java and OO features.
 Supports testing integrated classes (e.g., by default, no need to
create a new test class instance for every test method).
 Separates compile-time test code from run-time
configuration/data info.
 Flexible runtime configuration.
 Introduces ‘test groups’. Once you have compiled your tests, you
can just ask TestNG to run all the "front-end" tests, or "fast",
"slow", "database" tests, etc.
 Supports Dependent test methods, parallel testing, load testing,
and partial failure.
 Flexible plug-in API.
 Support for multi threaded testing.
procedure of the TestNG test API methods with an
example.
 import org.testng.annotations.Test;
 import org.testng.annotations.BeforeMethod;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.AfterClass;
 import org.testng.annotations.BeforeTest;
 import org.testng.annotations.AfterTest;
 import org.testng.annotations.BeforeSuite;
 import org.testng.annotations.AfterSuite;
 public class TestngAnnotation {
 // test case 1
 @Test
 public void testCase1() {
 System.out.println("in test case 1");
 }
 // test case 2
 @Test
 public void testCase2() {
 System.out.println("in test case 2");
 }
 @BeforeMethod
 public void beforeMethod() {
 System.out.println("in beforeMethod");
 }
 @AfterMethod
 public void afterMethod() {
 System.out.println("in afterMethod");
 }
 @BeforeClass
 public void beforeClass() {
 System.out.println("in beforeClass");
 }
 @AfterClass
 public void afterClass() {
 System.out.println("in afterClass");
 }
 @BeforeTest
 public void beforeTest() {
 System.out.println("in beforeTest");
 }
 @AfterTest
 public void afterTest() {
 System.out.println("in afterTest");
 }
 @BeforeSuite
 public void beforeSuite() {
 System.out.println("in beforeSuite");
 }
 @AfterSuite
 public void afterSuite() {
 System.out.println("in afterSuite");
 }
 create the
file testng.xml in C:>TestNG_WORKSPACE to execute
annotations.
 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE
suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite
name="Suite1"> <test name="test1"> <classes> <class
name="TestngAnnotation"/> </classes> </test>
</suite>Compile the Test case class using javac.
 C:TestNG_WORKSPACE>javac TestngAnnotation.java
 Now, run the testng.xml, which will run the test case
defined in the provided Test Case class.
 C:TestNG_WORKSPACE>java org.testng.TestNG
testng.xml
 Verify the output.
 in beforeSuite
 in beforeTest
 in beforeClass
 in beforeMethod
 in test case 1
 in afterMethod
 in beforeMethod
 in test case 2 in
 afterMethod in
 afterClass in
 afterTest I
 n afterSuite =============================================== Suite
Total tests run: 2, Failures: 0, Skips: 0
 Based on the above output, the execution procedure is as
follows:
 First of all, beforeSuite() method is executed only once.
 Lastly, the afterSuite() method executes only once.
 Even the methods beforeTest(), beforeClass(), afterClass(),
and afterTest() methods are executed only once.
 beforeMethod() method executes for each test case but
before executing the test case.
 afterMethod() method executes for each test case but after
executing the test case.
 In between beforeMethod() and afterMethod(), each test
case executes.
TestNG Hello World Example
 A classic example, show you how to get started with TestNG
unit test framework.
 Tools used :
 TestNG 6.8.7
 Maven 3
 Eclipse IDE
 1. TestNG Dependency
 Add TestNG library in the pom.xml.
 pom.xml
 <dependency> <groupId>org.testng</groupId>
<artifactId>testng</artifactId> <version>6.8.7</version>
<scope>test</scope> </dependency>
 2. TestNG Example
 Review a simple class, has a method to return a fixed
email “feedback@yoursite.com”.
 RandomEmailGenerator.java
 package com.mkyong.testng.project.service.email;
import org.springframework.stereotype.Service; public
class RandomEmailGenerator { public String
generate() { return "feedback@yoursite.com"; } }
Create a test case like this :
 TestHelloWorld.java
 package com.mkyong.testng.examples.helloworld; import
org.testng.Assert;
 import org.testng.annotations.Test;
 import
com.mkyong.testng.project.service.email.RandomEmailGenerator;
 public class TestHelloWorld {
 @Test() public void testEmailGenerator() {
 RandomEmailGenerator obj = new RandomEmailGenerator(); String
email = obj.generate();
 Assert.assertNotNull(email);
 Assert.assertEquals(email, "feedback@yoursite.com");
 }
 }
Test ng tutorial
Result
Ad

More Related Content

What's hot (20)

Test NG Framework Complete Walk Through
Test NG Framework Complete Walk ThroughTest NG Framework Complete Walk Through
Test NG Framework Complete Walk Through
Narendran Solai Sridharan
 
TestNG Framework
TestNG Framework TestNG Framework
TestNG Framework
Levon Apreyan
 
Setting up Page Object Model in Automation Framework
Setting up Page Object Model in Automation FrameworkSetting up Page Object Model in Automation Framework
Setting up Page Object Model in Automation Framework
valuebound
 
Java Unit Testing
Java Unit TestingJava Unit Testing
Java Unit Testing
Nayanda Haberty
 
TestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | EdurekaTestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | Edureka
Edureka!
 
Selenium WebDriver
Selenium WebDriverSelenium WebDriver
Selenium WebDriver
Rajathi-QA
 
Angular Unit Testing
Angular Unit TestingAngular Unit Testing
Angular Unit Testing
Alessandro Giorgetti
 
Unit Testing in Java
Unit Testing in JavaUnit Testing in Java
Unit Testing in Java
Ahmed M. Gomaa
 
TestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit TestingTestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit Testing
Bethmi Gunasekara
 
Selenium Automation Framework
Selenium Automation  FrameworkSelenium Automation  Framework
Selenium Automation Framework
Mindfire Solutions
 
Selenium Training | TestNG Framework For Selenium | Selenium Tutorial For Beg...
Selenium Training | TestNG Framework For Selenium | Selenium Tutorial For Beg...Selenium Training | TestNG Framework For Selenium | Selenium Tutorial For Beg...
Selenium Training | TestNG Framework For Selenium | Selenium Tutorial For Beg...
Edureka!
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
priya_trivedi
 
Unit Testing with Jest
Unit Testing with JestUnit Testing with Jest
Unit Testing with Jest
Maayan Glikser
 
Junit
JunitJunit
Junit
Vivek Kulkarni
 
Selenium Primer
Selenium PrimerSelenium Primer
Selenium Primer
gueste1e4db
 
Test Automation Framework Designs
Test Automation Framework DesignsTest Automation Framework Designs
Test Automation Framework Designs
Sauce Labs
 
Getting started with karate dsl
Getting started with karate dslGetting started with karate dsl
Getting started with karate dsl
Knoldus Inc.
 
[Flutter] 來體驗 bloc 小方塊的神奇魔法 @Devfest 2022
[Flutter] 來體驗 bloc 小方塊的神奇魔法 @Devfest 2022[Flutter] 來體驗 bloc 小方塊的神奇魔法 @Devfest 2022
[Flutter] 來體驗 bloc 小方塊的神奇魔法 @Devfest 2022
Johnny Sung
 
Java. Explicit and Implicit Wait. Testing Ajax Applications
Java. Explicit and Implicit Wait. Testing Ajax ApplicationsJava. Explicit and Implicit Wait. Testing Ajax Applications
Java. Explicit and Implicit Wait. Testing Ajax Applications
Марія Русин
 
Testing methodology
Testing methodologyTesting methodology
Testing methodology
Dina Hanbazazah
 
Setting up Page Object Model in Automation Framework
Setting up Page Object Model in Automation FrameworkSetting up Page Object Model in Automation Framework
Setting up Page Object Model in Automation Framework
valuebound
 
TestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | EdurekaTestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | Edureka
Edureka!
 
Selenium WebDriver
Selenium WebDriverSelenium WebDriver
Selenium WebDriver
Rajathi-QA
 
TestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit TestingTestNG - The Next Generation of Unit Testing
TestNG - The Next Generation of Unit Testing
Bethmi Gunasekara
 
Selenium Training | TestNG Framework For Selenium | Selenium Tutorial For Beg...
Selenium Training | TestNG Framework For Selenium | Selenium Tutorial For Beg...Selenium Training | TestNG Framework For Selenium | Selenium Tutorial For Beg...
Selenium Training | TestNG Framework For Selenium | Selenium Tutorial For Beg...
Edureka!
 
Unit Testing with Jest
Unit Testing with JestUnit Testing with Jest
Unit Testing with Jest
Maayan Glikser
 
Test Automation Framework Designs
Test Automation Framework DesignsTest Automation Framework Designs
Test Automation Framework Designs
Sauce Labs
 
Getting started with karate dsl
Getting started with karate dslGetting started with karate dsl
Getting started with karate dsl
Knoldus Inc.
 
[Flutter] 來體驗 bloc 小方塊的神奇魔法 @Devfest 2022
[Flutter] 來體驗 bloc 小方塊的神奇魔法 @Devfest 2022[Flutter] 來體驗 bloc 小方塊的神奇魔法 @Devfest 2022
[Flutter] 來體驗 bloc 小方塊的神奇魔法 @Devfest 2022
Johnny Sung
 
Java. Explicit and Implicit Wait. Testing Ajax Applications
Java. Explicit and Implicit Wait. Testing Ajax ApplicationsJava. Explicit and Implicit Wait. Testing Ajax Applications
Java. Explicit and Implicit Wait. Testing Ajax Applications
Марія Русин
 

Viewers also liked (19)

Introduction of TestNG framework and its benefits over Junit framework
Introduction of TestNG framework and its benefits over Junit frameworkIntroduction of TestNG framework and its benefits over Junit framework
Introduction of TestNG framework and its benefits over Junit framework
BugRaptors
 
TestNG vs. JUnit4
TestNG vs. JUnit4TestNG vs. JUnit4
TestNG vs. JUnit4
Andrey Oleynik
 
TestNg_Overview_Config
TestNg_Overview_ConfigTestNg_Overview_Config
TestNg_Overview_Config
Abhishek Chakraborty
 
Test ng for testers
Test ng for testersTest ng for testers
Test ng for testers
Colombo Selenium Meetup
 
Hybrid Automation Framework
Hybrid Automation FrameworkHybrid Automation Framework
Hybrid Automation Framework
ASHIRVAD MISHRA
 
TestNG vs JUnit: cease fire or the end of the war
TestNG vs JUnit: cease fire or the end of the warTestNG vs JUnit: cease fire or the end of the war
TestNG vs JUnit: cease fire or the end of the war
Oleksiy Rezchykov
 
TestNG introduction
TestNG introductionTestNG introduction
TestNG introduction
Denis Bazhin
 
Automation Testing using Selenium
Automation Testing using SeleniumAutomation Testing using Selenium
Automation Testing using Selenium
Naresh Chintalcheru
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
Pavan Kumar
 
2015-StarWest presentation on REST-assured
2015-StarWest presentation on REST-assured2015-StarWest presentation on REST-assured
2015-StarWest presentation on REST-assured
Eing Ong
 
API Testing
API TestingAPI Testing
API Testing
Bikash Sharma
 
Using Selenium 3 0
Using Selenium 3 0Using Selenium 3 0
Using Selenium 3 0
TEST Huddle
 
REST API testing with SpecFlow
REST API testing with SpecFlowREST API testing with SpecFlow
REST API testing with SpecFlow
Aiste Stikliute
 
How to Automate API Testing
How to Automate API TestingHow to Automate API Testing
How to Automate API Testing
Bruno Pedro
 
10 Benefits of Automated Testing
10 Benefits of Automated Testing10 Benefits of Automated Testing
10 Benefits of Automated Testing
TestObject - Mobile Testing
 
Selenium Tutorial For Beginners | What Is Selenium? | Selenium Automation Tes...
Selenium Tutorial For Beginners | What Is Selenium? | Selenium Automation Tes...Selenium Tutorial For Beginners | What Is Selenium? | Selenium Automation Tes...
Selenium Tutorial For Beginners | What Is Selenium? | Selenium Automation Tes...
Edureka!
 
Automation Testing by Selenium Web Driver
Automation Testing by Selenium Web DriverAutomation Testing by Selenium Web Driver
Automation Testing by Selenium Web Driver
Cuelogic Technologies Pvt. Ltd.
 
Test automation Frame Works
Test automation Frame WorksTest automation Frame Works
Test automation Frame Works
vodQA
 
Stand up
Stand upStand up
Stand up
vodQA
 
Introduction of TestNG framework and its benefits over Junit framework
Introduction of TestNG framework and its benefits over Junit frameworkIntroduction of TestNG framework and its benefits over Junit framework
Introduction of TestNG framework and its benefits over Junit framework
BugRaptors
 
Hybrid Automation Framework
Hybrid Automation FrameworkHybrid Automation Framework
Hybrid Automation Framework
ASHIRVAD MISHRA
 
TestNG vs JUnit: cease fire or the end of the war
TestNG vs JUnit: cease fire or the end of the warTestNG vs JUnit: cease fire or the end of the war
TestNG vs JUnit: cease fire or the end of the war
Oleksiy Rezchykov
 
TestNG introduction
TestNG introductionTestNG introduction
TestNG introduction
Denis Bazhin
 
Automation Testing using Selenium
Automation Testing using SeleniumAutomation Testing using Selenium
Automation Testing using Selenium
Naresh Chintalcheru
 
2015-StarWest presentation on REST-assured
2015-StarWest presentation on REST-assured2015-StarWest presentation on REST-assured
2015-StarWest presentation on REST-assured
Eing Ong
 
Using Selenium 3 0
Using Selenium 3 0Using Selenium 3 0
Using Selenium 3 0
TEST Huddle
 
REST API testing with SpecFlow
REST API testing with SpecFlowREST API testing with SpecFlow
REST API testing with SpecFlow
Aiste Stikliute
 
How to Automate API Testing
How to Automate API TestingHow to Automate API Testing
How to Automate API Testing
Bruno Pedro
 
Selenium Tutorial For Beginners | What Is Selenium? | Selenium Automation Tes...
Selenium Tutorial For Beginners | What Is Selenium? | Selenium Automation Tes...Selenium Tutorial For Beginners | What Is Selenium? | Selenium Automation Tes...
Selenium Tutorial For Beginners | What Is Selenium? | Selenium Automation Tes...
Edureka!
 
Test automation Frame Works
Test automation Frame WorksTest automation Frame Works
Test automation Frame Works
vodQA
 
Stand up
Stand upStand up
Stand up
vodQA
 
Ad

Similar to Test ng tutorial (20)

Test ng
Test ngTest ng
Test ng
Ramakrishna kapa
 
Testing with Junit4
Testing with Junit4Testing with Junit4
Testing with Junit4
Amila Paranawithana
 
Junit 4.0
Junit 4.0Junit 4.0
Junit 4.0
pallavikhandekar212
 
Session 4 -Junit- Testing Exceptions, Junit hooks.pptx
Session 4 -Junit- Testing Exceptions, Junit hooks.pptxSession 4 -Junit- Testing Exceptions, Junit hooks.pptx
Session 4 -Junit- Testing Exceptions, Junit hooks.pptx
trainingdecorpo
 
8-testing.pptx
8-testing.pptx8-testing.pptx
8-testing.pptx
ssuserd0fdaa
 
J unit presentation
J unit presentationJ unit presentation
J unit presentation
Priya Sharma
 
3 j unit
3 j unit3 j unit
3 j unit
kishoregali
 
Junit
JunitJunit
Junit
Abdullah Shahneel
 
Introduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylightIntroduction to JUnit testing in OpenDaylight
Introduction to JUnit testing in OpenDaylight
OpenDaylight
 
TestNG vs Junit
TestNG vs JunitTestNG vs Junit
TestNG vs Junit
Büşra İçöz
 
Junit With Eclipse
Junit With EclipseJunit With Eclipse
Junit With Eclipse
Sunil kumar Mohanty
 
Introduction to JUnit
Introduction to JUnitIntroduction to JUnit
Introduction to JUnit
Devvrat Shukla
 
JUnit
JUnitJUnit
JUnit
Li-Wei Cheng
 
unit 1 (1).pptx
unit 1 (1).pptxunit 1 (1).pptx
unit 1 (1).pptx
SumitKumar918321
 
Junit and testNG
Junit and testNGJunit and testNG
Junit and testNG
Марія Русин
 
Unit testing with JUnit
Unit testing with JUnitUnit testing with JUnit
Unit testing with JUnit
Pokpitch Patcharadamrongkul
 
Software Testing and JUnit and Best Practices
Software Testing and JUnit and Best PracticesSoftware Testing and JUnit and Best Practices
Software Testing and JUnit and Best Practices
ssuserbad56d
 
Unit Testing - Nakov's Talk @ VarnaConf 2013
Unit Testing - Nakov's Talk @ VarnaConf 2013Unit Testing - Nakov's Talk @ VarnaConf 2013
Unit Testing - Nakov's Talk @ VarnaConf 2013
Svetlin Nakov
 
Unit testing by Svetlin Nakov
Unit testing by Svetlin NakovUnit testing by Svetlin Nakov
Unit testing by Svetlin Nakov
it-tour
 
Unit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran JanardhanaUnit Testing with JUnit4 by Ravikiran Janardhana
Unit Testing with JUnit4 by Ravikiran Janardhana
Ravikiran J
 
Ad

More from Srikrishna k (16)

Android
AndroidAndroid
Android
Srikrishna k
 
Hsqldb tutorial
Hsqldb tutorialHsqldb tutorial
Hsqldb tutorial
Srikrishna k
 
S3inmule
S3inmuleS3inmule
S3inmule
Srikrishna k
 
Mule sqs
Mule sqsMule sqs
Mule sqs
Srikrishna k
 
Apachepoitutorial
ApachepoitutorialApachepoitutorial
Apachepoitutorial
Srikrishna k
 
Introduction testingmule
Introduction testingmuleIntroduction testingmule
Introduction testingmule
Srikrishna k
 
Designpattern
DesignpatternDesignpattern
Designpattern
Srikrishna k
 
Java util
Java utilJava util
Java util
Srikrishna k
 
Kafka tutorial
Kafka tutorialKafka tutorial
Kafka tutorial
Srikrishna k
 
Webservices intro
Webservices introWebservices intro
Webservices intro
Srikrishna k
 
Easy mock
Easy mockEasy mock
Easy mock
Srikrishna k
 
Apache kafka
Apache kafkaApache kafka
Apache kafka
Srikrishna k
 
Apachespark 160612140708
Apachespark 160612140708Apachespark 160612140708
Apachespark 160612140708
Srikrishna k
 
Vmtransport 160723040146
Vmtransport 160723040146Vmtransport 160723040146
Vmtransport 160723040146
Srikrishna k
 
Groovydemo 160721051742
Groovydemo 160721051742Groovydemo 160721051742
Groovydemo 160721051742
Srikrishna k
 
Apache kafka
Apache kafkaApache kafka
Apache kafka
Srikrishna k
 

Recently uploaded (20)

Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
Download Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With LatestDownload Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With Latest
tahirabibi60507
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Ranjan Baisak
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
steaveroggers
 
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025Why Orangescrum Is a Game Changer for Construction Companies in 2025
Why Orangescrum Is a Game Changer for Construction Companies in 2025
Orangescrum
 
Download Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With LatestDownload Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With Latest
tahirabibi60507
 
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and CollaborateMeet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Meet the Agents: How AI Is Learning to Think, Plan, and Collaborate
Maxim Salnikov
 
Kubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptxKubernetes_101_Zero_to_Platform_Engineer.pptx
Kubernetes_101_Zero_to_Platform_Engineer.pptx
CloudScouts
 
Expand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchangeExpand your AI adoption with AgentExchange
Expand your AI adoption with AgentExchange
Fexle Services Pvt. Ltd.
 
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Requirements in Engineering AI- Enabled Systems: Open Problems and Safe AI Sy...
Lionel Briand
 
How to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud PerformanceHow to Optimize Your AWS Environment for Improved Cloud Performance
How to Optimize Your AWS Environment for Improved Cloud Performance
ThousandEyes
 
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Proactive Vulnerability Detection in Source Code Using Graph Neural Networks:...
Ranjan Baisak
 
Download YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full ActivatedDownload YouTube By Click 2025 Free Full Activated
Download YouTube By Click 2025 Free Full Activated
saniamalik72555
 
Revolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptxRevolutionizing Residential Wi-Fi PPT.pptx
Revolutionizing Residential Wi-Fi PPT.pptx
nidhisingh691197
 
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software DevelopmentSecure Test Infrastructure: The Backbone of Trustworthy Software Development
Secure Test Infrastructure: The Backbone of Trustworthy Software Development
Shubham Joshi
 
Douwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License codeDouwan Crack 2025 new verson+ License code
Douwan Crack 2025 new verson+ License code
aneelaramzan63
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
Landscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature ReviewLandscape of Requirements Engineering for/by AI through Literature Review
Landscape of Requirements Engineering for/by AI through Literature Review
Hironori Washizaki
 
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...Explaining GitHub Actions Failures with Large Language Models Challenges, In...
Explaining GitHub Actions Failures with Large Language Models Challenges, In...
ssuserb14185
 
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
TestMigrationsInPy: A Dataset of Test Migrations from Unittest to Pytest (MSR...
Andre Hora
 
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Salesforce Data Cloud- Hyperscale data platform, built for Salesforce.
Dele Amefo
 
FL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full VersionFL Studio Producer Edition Crack 2025 Full Version
FL Studio Producer Edition Crack 2025 Full Version
tahirabibi60507
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
How to Batch Export Lotus Notes NSF Emails to Outlook PST Easily?
steaveroggers
 

Test ng tutorial

  • 1. TestNG is a testing framework developed in the lines of JUnit and NUnit, however it introduces some new functionalities that make it more powerful and easier to use. TestNG is designed to cover all categories of tests − unit, functional, end-to-end, integration, etc., and it requires JDK 5 or higher.
  • 2. What is TestNG?  TestNG is an open source automated testing framework; where NG meansNext Generation. TestNG is similar to JUnit (especially JUnit 4), but it is not a JUnit extension. It is inspired by JUnit. It is designed to be better than JUnit, especially when testing integrated classes. The creator of TestNG is Cedric Beust.
  • 3. TestNG Features  Supports annotations.  TestNG uses more Java and OO features.  Supports testing integrated classes (e.g., by default, no need to create a new test class instance for every test method).  Separates compile-time test code from run-time configuration/data info.  Flexible runtime configuration.  Introduces ‘test groups’. Once you have compiled your tests, you can just ask TestNG to run all the "front-end" tests, or "fast", "slow", "database" tests, etc.  Supports Dependent test methods, parallel testing, load testing, and partial failure.  Flexible plug-in API.  Support for multi threaded testing.
  • 4. procedure of the TestNG test API methods with an example.  import org.testng.annotations.Test;  import org.testng.annotations.BeforeMethod;  import org.testng.annotations.AfterMethod;  import org.testng.annotations.BeforeClass;  import org.testng.annotations.AfterClass;  import org.testng.annotations.BeforeTest;  import org.testng.annotations.AfterTest;  import org.testng.annotations.BeforeSuite;  import org.testng.annotations.AfterSuite;  public class TestngAnnotation {  // test case 1  @Test  public void testCase1() {  System.out.println("in test case 1");  }  // test case 2  @Test  public void testCase2() {  System.out.println("in test case 2");  }  @BeforeMethod  public void beforeMethod() {  System.out.println("in beforeMethod");  }  @AfterMethod  public void afterMethod() {  System.out.println("in afterMethod");  }
  • 5.  @BeforeClass  public void beforeClass() {  System.out.println("in beforeClass");  }  @AfterClass  public void afterClass() {  System.out.println("in afterClass");  }  @BeforeTest  public void beforeTest() {  System.out.println("in beforeTest");  }  @AfterTest  public void afterTest() {  System.out.println("in afterTest");  }  @BeforeSuite  public void beforeSuite() {  System.out.println("in beforeSuite");  }  @AfterSuite  public void afterSuite() {  System.out.println("in afterSuite");  }
  • 6.  create the file testng.xml in C:>TestNG_WORKSPACE to execute annotations.  <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" > <suite name="Suite1"> <test name="test1"> <classes> <class name="TestngAnnotation"/> </classes> </test> </suite>Compile the Test case class using javac.  C:TestNG_WORKSPACE>javac TestngAnnotation.java  Now, run the testng.xml, which will run the test case defined in the provided Test Case class.  C:TestNG_WORKSPACE>java org.testng.TestNG testng.xml
  • 7.  Verify the output.  in beforeSuite  in beforeTest  in beforeClass  in beforeMethod  in test case 1  in afterMethod  in beforeMethod  in test case 2 in  afterMethod in  afterClass in  afterTest I  n afterSuite =============================================== Suite Total tests run: 2, Failures: 0, Skips: 0
  • 8.  Based on the above output, the execution procedure is as follows:  First of all, beforeSuite() method is executed only once.  Lastly, the afterSuite() method executes only once.  Even the methods beforeTest(), beforeClass(), afterClass(), and afterTest() methods are executed only once.  beforeMethod() method executes for each test case but before executing the test case.  afterMethod() method executes for each test case but after executing the test case.  In between beforeMethod() and afterMethod(), each test case executes.
  • 9. TestNG Hello World Example  A classic example, show you how to get started with TestNG unit test framework.  Tools used :  TestNG 6.8.7  Maven 3  Eclipse IDE  1. TestNG Dependency  Add TestNG library in the pom.xml.  pom.xml  <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>6.8.7</version> <scope>test</scope> </dependency>
  • 10.  2. TestNG Example  Review a simple class, has a method to return a fixed email “[email protected]”.  RandomEmailGenerator.java  package com.mkyong.testng.project.service.email; import org.springframework.stereotype.Service; public class RandomEmailGenerator { public String generate() { return "[email protected]"; } }
  • 11. Create a test case like this :  TestHelloWorld.java  package com.mkyong.testng.examples.helloworld; import org.testng.Assert;  import org.testng.annotations.Test;  import com.mkyong.testng.project.service.email.RandomEmailGenerator;  public class TestHelloWorld {  @Test() public void testEmailGenerator() {  RandomEmailGenerator obj = new RandomEmailGenerator(); String email = obj.generate();  Assert.assertNotNull(email);  Assert.assertEquals(email, "[email protected]");  }  }