SlideShare uma empresa Scribd logo
1 de 26
Baixar para ler offline
TestNg Overview and Configuration in eclipse
1 Abhishek Chakraborty (abhishek.tec@gmail.com)
 What is TestNG?
TestNG is testing framework used for the Java
programming language. TestNG is the framework which is
very useful to use with selenium WebDriver software
testing tool. The TestNG framework is introduced to
overcome the limitations of JUnit framework. Most of
the automation users are using this framework because
of its advantages & more supported features. Using this
TestNG framework we will learn how to generate test
reports. Also we can use Ant and xslt report along with
TestNg.
 Features of TestNG Framework:
TestNG supports many powerful features & it is easy to
use. Let’s see what all new features are supported in
new testing framework:
 Support for parameters.
 Supports dependent methods testing.
 Test configuration flexible.
 Supports powerful execution model.
 TestNG has a more elegant way of handling
parameterized tests with the data-provider concept.
 For the same test class TestNG support for multiple
instances.
 Default JDK functions for runtime and logging (no
dependencies).
 Supported different Annotations like @BeforeSuite,
@AfterSuite, @BeforeClass, @AfterClass,
@BeforeTest, @AfterTest, @BeforeMethod,
@AfterMethod, @DataProvider, @Parameters, @Test
etc.
TestNG supports annotations which are very helpful to
guide test case executions. Similarly in JUnit, the
TestNG annotations are always preceded by the ‘@’
symbol. It permit you do parallel execution of test
TestNg Overview and Configuration in eclipse
2 Abhishek Chakraborty (abhishek.tec@gmail.com)
cases & we can also skip the test cases effortlessly
while executing test cases.
TestNG is specially designed to cover all types testing
categories like Unit, Functional testing, Integration
testing, End-to-end etc. Using TestNG framework allows
us to generate test reports in both HTML and XML
formats. Using ANT with TestNG, we can generate
primitive Testng reports as well.
 Advantages of TestNG over Junit:
1.In TestNG Annotations are easy to understand over
JUnit.
2.In TestNG there is no constraint like you have to
declare @BeforeClass and @AfterClass
3.As method name constraint is present in JUnit, such
method name constraint is not present in TestNG and
you can specify any test method names.
4.In TestNG enable you to grouping of test cases
easily which is not possible in JUnit.
5.TestNG supports following three 3 additional
setUp/tearDown level:
@Before/AfterSuite, @Before/AfterTest and
@Before/AfterGroup.
6.TestNG allows us to define the dependent test
7.Parallel execution of Selenium test cases is
possible in TestNG.
TestNg Overview and Configuration in eclipse
3 Abhishek Chakraborty (abhishek.tec@gmail.com)
 Steps to install TestNG in Eclipse IDE:
1) Launch Eclipse IDE & under Help menu click on
“Install New Software” option.
TestNg Overview and Configuration in eclipse
4 Abhishek Chakraborty (abhishek.tec@gmail.com)
2) Install dialog box will be appeared same as below:
TestNg Overview and Configuration in eclipse
5 Abhishek Chakraborty (abhishek.tec@gmail.com)
3) In the install dialog box, enter URL as
“http://beust.com/eclipse” in Work with text box &
press keyboard enter key.
TestNg Overview and Configuration in eclipse
6 Abhishek Chakraborty (abhishek.tec@gmail.com)
4) Under Name column TestNG check box will be displayed
same as below:
TestNg Overview and Configuration in eclipse
7 Abhishek Chakraborty (abhishek.tec@gmail.com)
5) Select the “TestNG” check box & click on Next
button.
TestNg Overview and Configuration in eclipse
8 Abhishek Chakraborty (abhishek.tec@gmail.com)
6) On Install Details screen, make sure that TestNG is
selected & then click on Next button same as mentioned
below screenshot:
TestNg Overview and Configuration in eclipse
9 Abhishek Chakraborty (abhishek.tec@gmail.com)
7) On Review Licenses screen read license agreement &
select “I accept…” option shown in below screen shot &
click on Finish button.
TestNg Overview and Configuration in eclipse
10 Abhishek Chakraborty (abhishek.tec@gmail.com)
8) Ensure that Installing Software dialog appear. Wait
till installation gets completed:
9) One security warning message will appear during
installation. Ensure that you click on Ok button if
same security dialog is appeared.
10) Once the installation process is completed then
Eclipse ask you to Restart, click on Yes button.
TestNg Overview and Configuration in eclipse
11 Abhishek Chakraborty (abhishek.tec@gmail.com)
11) Once the Eclipse is restarted, to make sure whether
TestNG is installed or not. Just under Run menu click
on “Run As” option & check new option is added called
“TestNG Test”same as below screen shot:
TestNg Overview and Configuration in eclipse
12 Abhishek Chakraborty (abhishek.tec@gmail.com)
 Creating Java Project with TestNG Dependencies
Before we write our first TestNG test, we have to
create a Java project in Eclipse and add our TestNG
test dependencies.
1) Go to File | New | Other. A window with multiple
options will be shown.
2) Select Java Project as shown in the following
screenshot and click on Next.
TestNg Overview and Configuration in eclipse
13 Abhishek Chakraborty (abhishek.tec@gmail.com)
3) On the next screen, enter a Project name for a
Java project, let’s say TestNGExamples, as shown in
the following screenshot, and click on Finish:
This will create a new Java project in Eclipse.
TestNg Overview and Configuration in eclipse
14 Abhishek Chakraborty (abhishek.tec@gmail.com)
4)Now go to Project | Properties. Select Java Build
Path on the left-hand side on the Properties window
as shown in the following screenshot. This will
display the build path for the newly created
project.
5) Click on the Libraries tab and click on the Add
Library… option.
TestNg Overview and Configuration in eclipse
15 Abhishek Chakraborty (abhishek.tec@gmail.com)
6) Select TestNG on the Add Library window as shown
in the following screenshot and click on Next:
TestNg Overview and Configuration in eclipse
16 Abhishek Chakraborty (abhishek.tec@gmail.com)
7) Click on Finish on your next window. This will
add the TestNG library to your Eclipse project.
We have successfully created a new Java project in
Eclipse and added a TestNG library to the build
path of the project.
TestNg Overview and Configuration in eclipse
17 Abhishek Chakraborty (abhishek.tec@gmail.com)
 Creating your first TestNG class
Perform the following steps to create your first
TestNG class:
1) Go to File | New | Other. This will open a new
Add wizard window in Eclipse.
TestNg Overview and Configuration in eclipse
18 Abhishek Chakraborty (abhishek.tec@gmail.com)
2) Select TestNG class from the Add wizard window
and click on Next.
TestNg Overview and Configuration in eclipse
19 Abhishek Chakraborty (abhishek.tec@gmail.com)
3) On the next window click on the Browse
button and select the Java project where you need
to add your class.
TestNg Overview and Configuration in eclipse
20 Abhishek Chakraborty (abhishek.tec@gmail.com)
4) Enter the package name and the test class
name and click on Finish.
TestNg Overview and Configuration in eclipse
21 Abhishek Chakraborty (abhishek.tec@gmail.com)
5) This window also gives you an option to select
different annotations while creating a new TestNG
class. If selected, the plugin will generate dummy
methods for these annotations while generating the
class. This will add a new TestNG class to your
project.
package com.howtodoinjava.test;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class MyFirstTest {
@Test
public void f() {
}
@BeforeTest
public void beforeTest() {
}
@AfterTest
public void afterTest() {
}
}
 We have successfully added a new TestNG test class
to the newly created Java project in Eclipse. Feel
free to modify the code as needed. Now let’s run
the newly created test class through Eclipse.
TestNg Overview and Configuration in eclipse
22 Abhishek Chakraborty (abhishek.tec@gmail.com)
Running TestNG test
Perform the following steps to run tests through
Eclipse:
1) Select the Java project in the Eclipse and go to Run
| Run Configuration.
2) Select TestNG in the given options and click on the
New button to create a new configuration.
TestNg Overview and Configuration in eclipse
23 Abhishek Chakraborty (abhishek.tec@gmail.com)
3) Please notice that TestNG plugin provides multiple
options for running your test cases as follows:
Class: Using this option you can provide the class
name along with the package to run only the said
specific test class.
Method: Using this you can run only a specific method
in a test class.
Groups: In case you would like to run specific test
methods belonging to a particular TestNG group, you can
enter those here for executing them.
Package: If you would like to execute all the tests
inside a package, you can specify these in this box.
Suite: In case you have suite files in the form
of testing.xml files, you can select those here for
execution.
TestNg Overview and Configuration in eclipse
24 Abhishek Chakraborty (abhishek.tec@gmail.com)
Let’s enter the configuration name as TestNGRunConfig and
select the newly created class under the Class section
and click on Apply.
4) Now if you would like to run the newly created
configuration, just click on Run after clicking on
Apply. This will compile and run the TestNG test class
that we have written. The result of the test execution
is displayed in the Console and Results windows of
Eclipse as shown in the following screenshot.
[TestNG] Running:
C:Userssomelocalpathtestng-customsuite.xml
PASSED: f
===============================================
Default test
Tests run: 1, Failures: 0, Skips: 0
===============================================
===============================================
Default suite
Total tests run: 1, Failures: 0, Skips: 0
===============================================
[TestNG] Time taken by org.testng.reporters.XMLReporter@177b3cd: 23 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 0 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@b8deef: 46 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@10ab323: 12 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter2@5e176f: 13 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@d1e89e: 142 ms
You can also run the test class by selecting it and
then right-clicking on it, selecting Run as from the
menu, and then choosing TestNG Test.
TestNg Overview and Configuration in eclipse
25 Abhishek Chakraborty (abhishek.tec@gmail.com)
TestNg Overview and Configuration in eclipse
26 Abhishek Chakraborty (abhishek.tec@gmail.com)
 Conclusion:
TestNG is really impressive framework where we can
execute the simple to complex test scripts with
ease. It supports many powerful features, like
annotations, reporting, data-driven testing etc.
You can develop page object model (POM) with Page
Factory framework with the help of Testng easily.
Also You can use ant with TestNg, generate
graphical report with the help of xslt report.
In this TestNG tutorial, we learned about TestNG,
features offered by TestNG, installing the TestNG
plugin into Eclipse and writing and executing a TestNG
test class through Eclipse
Happy Learning

Mais conteúdo relacionado

Mais procurados

TestNG introduction
TestNG introductionTestNG introduction
TestNG introductionDenis Bazhin
 
TestNG Session presented in PB
TestNG Session presented in PBTestNG Session presented in PB
TestNG Session presented in PBAbhishek Yadav
 
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 TestingBethmi Gunasekara
 
Junit4&testng presentation
Junit4&testng presentationJunit4&testng presentation
Junit4&testng presentationSanjib Dhar
 
TestNG Session presented in Xebia XKE
TestNG Session presented in Xebia XKETestNG Session presented in Xebia XKE
TestNG Session presented in Xebia XKEAbhishek Yadav
 
TestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | EdurekaTestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | EdurekaEdureka!
 
Selenium with testng and eclipse ide
Selenium with testng and eclipse ideSelenium with testng and eclipse ide
Selenium with testng and eclipse ideTestertester Jaipur
 
JUnit 5 - The Next Generation of JUnit - Ted's Tool Time
JUnit 5 - The Next Generation of JUnit - Ted's Tool TimeJUnit 5 - The Next Generation of JUnit - Ted's Tool Time
JUnit 5 - The Next Generation of JUnit - Ted's Tool TimeTed Vinke
 
Simple Unit Testing With Netbeans 6.1
Simple Unit Testing With Netbeans 6.1Simple Unit Testing With Netbeans 6.1
Simple Unit Testing With Netbeans 6.1Kiki Ahmadi
 
An Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
An Introduction to JUnit 5 and how to use it with Spring boot tests and MockitoAn Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
An Introduction to JUnit 5 and how to use it with Spring boot tests and Mockitoshaunthomas999
 

Mais procurados (20)

TestNG introduction
TestNG introductionTestNG introduction
TestNG introduction
 
TestNG Session presented in PB
TestNG Session presented in PBTestNG Session presented in PB
TestNG Session presented in PB
 
Test ng
Test ngTest ng
Test ng
 
TestNG vs. JUnit4
TestNG vs. JUnit4TestNG vs. JUnit4
TestNG vs. JUnit4
 
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
 
testng
testngtestng
testng
 
Junit and testNG
Junit and testNGJunit and testNG
Junit and testNG
 
Junit4&testng presentation
Junit4&testng presentationJunit4&testng presentation
Junit4&testng presentation
 
TestNG Session presented in Xebia XKE
TestNG Session presented in Xebia XKETestNG Session presented in Xebia XKE
TestNG Session presented in Xebia XKE
 
TestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | EdurekaTestNG Annotations in Selenium | Edureka
TestNG Annotations in Selenium | Edureka
 
Test ng
Test ngTest ng
Test ng
 
TestNG Data Binding
TestNG Data BindingTestNG Data Binding
TestNG Data Binding
 
Selenium TestNG
Selenium TestNGSelenium TestNG
Selenium TestNG
 
TestNG vs Junit
TestNG vs JunitTestNG vs Junit
TestNG vs Junit
 
Selenium with testng and eclipse ide
Selenium with testng and eclipse ideSelenium with testng and eclipse ide
Selenium with testng and eclipse ide
 
JUnit 5 - The Next Generation of JUnit - Ted's Tool Time
JUnit 5 - The Next Generation of JUnit - Ted's Tool TimeJUnit 5 - The Next Generation of JUnit - Ted's Tool Time
JUnit 5 - The Next Generation of JUnit - Ted's Tool Time
 
Selenium with java
Selenium with javaSelenium with java
Selenium with java
 
Simple Unit Testing With Netbeans 6.1
Simple Unit Testing With Netbeans 6.1Simple Unit Testing With Netbeans 6.1
Simple Unit Testing With Netbeans 6.1
 
Testing In Java
Testing In JavaTesting In Java
Testing In Java
 
An Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
An Introduction to JUnit 5 and how to use it with Spring boot tests and MockitoAn Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
An Introduction to JUnit 5 and how to use it with Spring boot tests and Mockito
 

Destaque

Page object with selenide
Page object with selenidePage object with selenide
Page object with selenideCOMAQA.BY
 
Hybrid Automation Framework
Hybrid Automation FrameworkHybrid Automation Framework
Hybrid Automation FrameworkASHIRVAD MISHRA
 
Testing RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured frameworkTesting RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured frameworkMicha Kops
 
2015-StarWest presentation on REST-assured
2015-StarWest presentation on REST-assured2015-StarWest presentation on REST-assured
2015-StarWest presentation on REST-assuredEing Ong
 
REST API testing with SpecFlow
REST API testing with SpecFlowREST API testing with SpecFlow
REST API testing with SpecFlowAiste Stikliute
 

Destaque (9)

Page object with selenide
Page object with selenidePage object with selenide
Page object with selenide
 
Hybrid Automation Framework
Hybrid Automation FrameworkHybrid Automation Framework
Hybrid Automation Framework
 
Testing RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured frameworkTesting RESTful Webservices using the REST-assured framework
Testing RESTful Webservices using the REST-assured framework
 
2015-StarWest presentation on REST-assured
2015-StarWest presentation on REST-assured2015-StarWest presentation on REST-assured
2015-StarWest presentation on REST-assured
 
Rest assured
Rest assuredRest assured
Rest assured
 
BDD for APIs
BDD for APIsBDD for APIs
BDD for APIs
 
REST API testing with SpecFlow
REST API testing with SpecFlowREST API testing with SpecFlow
REST API testing with SpecFlow
 
10 Benefits of Automated Testing
10 Benefits of Automated Testing10 Benefits of Automated Testing
10 Benefits of Automated Testing
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
 

Semelhante a TestNg_Overview_Config

Junit Test Cases
Junit Test CasesJunit Test Cases
Junit Test CasesInno Ly
 
How To Install TestNG in Eclipse Step By Step Guide.pdf
How To Install TestNG in Eclipse Step By Step Guide.pdfHow To Install TestNG in Eclipse Step By Step Guide.pdf
How To Install TestNG in Eclipse Step By Step Guide.pdfpCloudy
 
J unit presentation
J unit presentationJ unit presentation
J unit presentationPriya Sharma
 
Introduction to test automation in java and php
Introduction to test automation in java and phpIntroduction to test automation in java and php
Introduction to test automation in java and phpTho Q Luong Luong
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkOnkar Deshpande
 
Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012Hazem Saleh
 
Integrating Maven with Eclipse
Integrating Maven with EclipseIntegrating Maven with Eclipse
Integrating Maven with EclipseNikhil Bharati
 
Efficient JavaScript Unit Testing, March 2013
Efficient JavaScript Unit Testing, March 2013Efficient JavaScript Unit Testing, March 2013
Efficient JavaScript Unit Testing, March 2013Hazem Saleh
 
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex ScenariosUnit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex ScenariosFlutter Agency
 
Embrace Unit Testing
Embrace Unit TestingEmbrace Unit Testing
Embrace Unit Testingalessiopace
 
.Net Unit Testing with Visual Studio 2010
.Net Unit Testing with Visual Studio 2010.Net Unit Testing with Visual Studio 2010
.Net Unit Testing with Visual Studio 2010kgayda
 

Semelhante a TestNg_Overview_Config (20)

Junit Test Cases
Junit Test CasesJunit Test Cases
Junit Test Cases
 
How To Install TestNG in Eclipse Step By Step Guide.pdf
How To Install TestNG in Eclipse Step By Step Guide.pdfHow To Install TestNG in Eclipse Step By Step Guide.pdf
How To Install TestNG in Eclipse Step By Step Guide.pdf
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
J unit presentation
J unit presentationJ unit presentation
J unit presentation
 
JUnit Presentation
JUnit PresentationJUnit Presentation
JUnit Presentation
 
Introduction to test automation in java and php
Introduction to test automation in java and phpIntroduction to test automation in java and php
Introduction to test automation in java and php
 
8-testing.pptx
8-testing.pptx8-testing.pptx
8-testing.pptx
 
JUnit- A Unit Testing Framework
JUnit- A Unit Testing FrameworkJUnit- A Unit Testing Framework
JUnit- A Unit Testing Framework
 
unit 1 (1).pptx
unit 1 (1).pptxunit 1 (1).pptx
unit 1 (1).pptx
 
Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012Efficient JavaScript Unit Testing, May 2012
Efficient JavaScript Unit Testing, May 2012
 
Integrating Maven with Eclipse
Integrating Maven with EclipseIntegrating Maven with Eclipse
Integrating Maven with Eclipse
 
New selenium rc
New selenium rcNew selenium rc
New selenium rc
 
N Unit Presentation
N Unit PresentationN Unit Presentation
N Unit Presentation
 
Unit Testing in Java
Unit Testing in JavaUnit Testing in Java
Unit Testing in Java
 
ikp321-04
ikp321-04ikp321-04
ikp321-04
 
Efficient JavaScript Unit Testing, March 2013
Efficient JavaScript Unit Testing, March 2013Efficient JavaScript Unit Testing, March 2013
Efficient JavaScript Unit Testing, March 2013
 
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex ScenariosUnit Testing in Flutter - From Workflow Essentials to Complex Scenarios
Unit Testing in Flutter - From Workflow Essentials to Complex Scenarios
 
Embrace Unit Testing
Embrace Unit TestingEmbrace Unit Testing
Embrace Unit Testing
 
About Selenium Webdriver
About Selenium WebdriverAbout Selenium Webdriver
About Selenium Webdriver
 
.Net Unit Testing with Visual Studio 2010
.Net Unit Testing with Visual Studio 2010.Net Unit Testing with Visual Studio 2010
.Net Unit Testing with Visual Studio 2010
 

TestNg_Overview_Config

  • 1. TestNg Overview and Configuration in eclipse 1 Abhishek Chakraborty (abhishek.tec@gmail.com)  What is TestNG? TestNG is testing framework used for the Java programming language. TestNG is the framework which is very useful to use with selenium WebDriver software testing tool. The TestNG framework is introduced to overcome the limitations of JUnit framework. Most of the automation users are using this framework because of its advantages & more supported features. Using this TestNG framework we will learn how to generate test reports. Also we can use Ant and xslt report along with TestNg.  Features of TestNG Framework: TestNG supports many powerful features & it is easy to use. Let’s see what all new features are supported in new testing framework:  Support for parameters.  Supports dependent methods testing.  Test configuration flexible.  Supports powerful execution model.  TestNG has a more elegant way of handling parameterized tests with the data-provider concept.  For the same test class TestNG support for multiple instances.  Default JDK functions for runtime and logging (no dependencies).  Supported different Annotations like @BeforeSuite, @AfterSuite, @BeforeClass, @AfterClass, @BeforeTest, @AfterTest, @BeforeMethod, @AfterMethod, @DataProvider, @Parameters, @Test etc. TestNG supports annotations which are very helpful to guide test case executions. Similarly in JUnit, the TestNG annotations are always preceded by the ‘@’ symbol. It permit you do parallel execution of test
  • 2. TestNg Overview and Configuration in eclipse 2 Abhishek Chakraborty (abhishek.tec@gmail.com) cases & we can also skip the test cases effortlessly while executing test cases. TestNG is specially designed to cover all types testing categories like Unit, Functional testing, Integration testing, End-to-end etc. Using TestNG framework allows us to generate test reports in both HTML and XML formats. Using ANT with TestNG, we can generate primitive Testng reports as well.  Advantages of TestNG over Junit: 1.In TestNG Annotations are easy to understand over JUnit. 2.In TestNG there is no constraint like you have to declare @BeforeClass and @AfterClass 3.As method name constraint is present in JUnit, such method name constraint is not present in TestNG and you can specify any test method names. 4.In TestNG enable you to grouping of test cases easily which is not possible in JUnit. 5.TestNG supports following three 3 additional setUp/tearDown level: @Before/AfterSuite, @Before/AfterTest and @Before/AfterGroup. 6.TestNG allows us to define the dependent test 7.Parallel execution of Selenium test cases is possible in TestNG.
  • 3. TestNg Overview and Configuration in eclipse 3 Abhishek Chakraborty (abhishek.tec@gmail.com)  Steps to install TestNG in Eclipse IDE: 1) Launch Eclipse IDE & under Help menu click on “Install New Software” option.
  • 4. TestNg Overview and Configuration in eclipse 4 Abhishek Chakraborty (abhishek.tec@gmail.com) 2) Install dialog box will be appeared same as below:
  • 5. TestNg Overview and Configuration in eclipse 5 Abhishek Chakraborty (abhishek.tec@gmail.com) 3) In the install dialog box, enter URL as “http://beust.com/eclipse” in Work with text box & press keyboard enter key.
  • 6. TestNg Overview and Configuration in eclipse 6 Abhishek Chakraborty (abhishek.tec@gmail.com) 4) Under Name column TestNG check box will be displayed same as below:
  • 7. TestNg Overview and Configuration in eclipse 7 Abhishek Chakraborty (abhishek.tec@gmail.com) 5) Select the “TestNG” check box & click on Next button.
  • 8. TestNg Overview and Configuration in eclipse 8 Abhishek Chakraborty (abhishek.tec@gmail.com) 6) On Install Details screen, make sure that TestNG is selected & then click on Next button same as mentioned below screenshot:
  • 9. TestNg Overview and Configuration in eclipse 9 Abhishek Chakraborty (abhishek.tec@gmail.com) 7) On Review Licenses screen read license agreement & select “I accept…” option shown in below screen shot & click on Finish button.
  • 10. TestNg Overview and Configuration in eclipse 10 Abhishek Chakraborty (abhishek.tec@gmail.com) 8) Ensure that Installing Software dialog appear. Wait till installation gets completed: 9) One security warning message will appear during installation. Ensure that you click on Ok button if same security dialog is appeared. 10) Once the installation process is completed then Eclipse ask you to Restart, click on Yes button.
  • 11. TestNg Overview and Configuration in eclipse 11 Abhishek Chakraborty (abhishek.tec@gmail.com) 11) Once the Eclipse is restarted, to make sure whether TestNG is installed or not. Just under Run menu click on “Run As” option & check new option is added called “TestNG Test”same as below screen shot:
  • 12. TestNg Overview and Configuration in eclipse 12 Abhishek Chakraborty (abhishek.tec@gmail.com)  Creating Java Project with TestNG Dependencies Before we write our first TestNG test, we have to create a Java project in Eclipse and add our TestNG test dependencies. 1) Go to File | New | Other. A window with multiple options will be shown. 2) Select Java Project as shown in the following screenshot and click on Next.
  • 13. TestNg Overview and Configuration in eclipse 13 Abhishek Chakraborty (abhishek.tec@gmail.com) 3) On the next screen, enter a Project name for a Java project, let’s say TestNGExamples, as shown in the following screenshot, and click on Finish: This will create a new Java project in Eclipse.
  • 14. TestNg Overview and Configuration in eclipse 14 Abhishek Chakraborty (abhishek.tec@gmail.com) 4)Now go to Project | Properties. Select Java Build Path on the left-hand side on the Properties window as shown in the following screenshot. This will display the build path for the newly created project. 5) Click on the Libraries tab and click on the Add Library… option.
  • 15. TestNg Overview and Configuration in eclipse 15 Abhishek Chakraborty (abhishek.tec@gmail.com) 6) Select TestNG on the Add Library window as shown in the following screenshot and click on Next:
  • 16. TestNg Overview and Configuration in eclipse 16 Abhishek Chakraborty (abhishek.tec@gmail.com) 7) Click on Finish on your next window. This will add the TestNG library to your Eclipse project. We have successfully created a new Java project in Eclipse and added a TestNG library to the build path of the project.
  • 17. TestNg Overview and Configuration in eclipse 17 Abhishek Chakraborty (abhishek.tec@gmail.com)  Creating your first TestNG class Perform the following steps to create your first TestNG class: 1) Go to File | New | Other. This will open a new Add wizard window in Eclipse.
  • 18. TestNg Overview and Configuration in eclipse 18 Abhishek Chakraborty (abhishek.tec@gmail.com) 2) Select TestNG class from the Add wizard window and click on Next.
  • 19. TestNg Overview and Configuration in eclipse 19 Abhishek Chakraborty (abhishek.tec@gmail.com) 3) On the next window click on the Browse button and select the Java project where you need to add your class.
  • 20. TestNg Overview and Configuration in eclipse 20 Abhishek Chakraborty (abhishek.tec@gmail.com) 4) Enter the package name and the test class name and click on Finish.
  • 21. TestNg Overview and Configuration in eclipse 21 Abhishek Chakraborty (abhishek.tec@gmail.com) 5) This window also gives you an option to select different annotations while creating a new TestNG class. If selected, the plugin will generate dummy methods for these annotations while generating the class. This will add a new TestNG class to your project. package com.howtodoinjava.test; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; public class MyFirstTest { @Test public void f() { } @BeforeTest public void beforeTest() { } @AfterTest public void afterTest() { } }  We have successfully added a new TestNG test class to the newly created Java project in Eclipse. Feel free to modify the code as needed. Now let’s run the newly created test class through Eclipse.
  • 22. TestNg Overview and Configuration in eclipse 22 Abhishek Chakraborty (abhishek.tec@gmail.com) Running TestNG test Perform the following steps to run tests through Eclipse: 1) Select the Java project in the Eclipse and go to Run | Run Configuration. 2) Select TestNG in the given options and click on the New button to create a new configuration.
  • 23. TestNg Overview and Configuration in eclipse 23 Abhishek Chakraborty (abhishek.tec@gmail.com) 3) Please notice that TestNG plugin provides multiple options for running your test cases as follows: Class: Using this option you can provide the class name along with the package to run only the said specific test class. Method: Using this you can run only a specific method in a test class. Groups: In case you would like to run specific test methods belonging to a particular TestNG group, you can enter those here for executing them. Package: If you would like to execute all the tests inside a package, you can specify these in this box. Suite: In case you have suite files in the form of testing.xml files, you can select those here for execution.
  • 24. TestNg Overview and Configuration in eclipse 24 Abhishek Chakraborty (abhishek.tec@gmail.com) Let’s enter the configuration name as TestNGRunConfig and select the newly created class under the Class section and click on Apply. 4) Now if you would like to run the newly created configuration, just click on Run after clicking on Apply. This will compile and run the TestNG test class that we have written. The result of the test execution is displayed in the Console and Results windows of Eclipse as shown in the following screenshot. [TestNG] Running: C:Userssomelocalpathtestng-customsuite.xml PASSED: f =============================================== Default test Tests run: 1, Failures: 0, Skips: 0 =============================================== =============================================== Default suite Total tests run: 1, Failures: 0, Skips: 0 =============================================== [TestNG] Time taken by org.testng.reporters.XMLReporter@177b3cd: 23 ms [TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 0 ms [TestNG] Time taken by org.testng.reporters.jq.Main@b8deef: 46 ms [TestNG] Time taken by org.testng.reporters.JUnitReportReporter@10ab323: 12 ms [TestNG] Time taken by org.testng.reporters.EmailableReporter2@5e176f: 13 ms [TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@d1e89e: 142 ms You can also run the test class by selecting it and then right-clicking on it, selecting Run as from the menu, and then choosing TestNG Test.
  • 25. TestNg Overview and Configuration in eclipse 25 Abhishek Chakraborty (abhishek.tec@gmail.com)
  • 26. TestNg Overview and Configuration in eclipse 26 Abhishek Chakraborty (abhishek.tec@gmail.com)  Conclusion: TestNG is really impressive framework where we can execute the simple to complex test scripts with ease. It supports many powerful features, like annotations, reporting, data-driven testing etc. You can develop page object model (POM) with Page Factory framework with the help of Testng easily. Also You can use ant with TestNg, generate graphical report with the help of xslt report. In this TestNG tutorial, we learned about TestNG, features offered by TestNG, installing the TestNG plugin into Eclipse and writing and executing a TestNG test class through Eclipse Happy Learning