TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Automation

TestNG Automation Framework Questions

In this post, lets look into some of the TestNG automation framework questions and answers to them.

What is TestNG framework ?

TestNG is inspired by JUnit and NUnit frameworks. It is an open-source framework for functional test automation. It provides an API for adding custom implementations as well. Also, TestNG has a better reporting structure and it provides XML and HTML default reports.TestNG is primarily used for functional testing, unlike JUnit which is mostly used for unit testing. In addition, we can drive testng different configuration runs using the XML file. Furthermore, TestNG methods are specified with @Test annotation in the code.

What are TestNG framework features?

Main TestNG features are:

  • Support for different annotations.
  • Flexibility using XML test suite file.
  • Test Parameters.
  • Test Groups.
  • Test Dependencies.
  • Parallel testing.
  • Data-driven testing using – @DataProvider, @Factory
  • Test Reports
  • Open API
  • Ability to run failed Tests

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

What is method dependency in TestNG?

Sample snippet below that depicts method dependency in TestNG framework.

@Test() 
 public void method1(){ 
 System.out.println("method1"); 
 } 
  
   
 @Test(dependsOnMethods={"method1"}) 
 public void dependent(){ 
 System.out.println("This method depends on method1, this method will  
skip if method1 fails"); 
 }

 

What is @Factory annotation in TestNG?

@Factory in TestNG framework creates tests dynamically at run-time. A factory method is defined by declaring @Factory above the respective test method. It is mandatory that a factory method should return an array of Object  i.e Object[]
TestNG factory is used to create instances of test classes. This is useful if you want to run the test class any no of times.

Example code snippet:

 
public class SampleFactory
 {
  @Factory
  public Object[] factoryMethod()
 {
  Object[] object = new Object[5];
  for (int i = 0; i < 5 ; i++)
     {
     object[i] = new SampleTest();
       }
  return object;
  }
 }

 

Related Posts

Emma Tool

Automation /

Code Coverage Tools

Selenium 4 Automation Project

Automation /

Selenium 4 Project Setup on Ubuntu Linux

Testing webpage mobile-friendliness using a tool

Automation /

Testing webpage mobile-friendliness using a tool

Errors Code Testing Development

Automation /

Error Severity Metrics

Automation Environment Setup Verification

Automation /

Automation Environment Setup Verification

‹ Unix Operating System for Beginners› JMeter Performance Testing Questions

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version