TestNG is a testing framework for the Java programming language created by Cédric Beust and inspired by JUnit and NUnit. The design goal of TestNG is to cover a wider range of test categories: unit, functional, end-to-end, integration, etc., with more powerful and easy-to-use functionalities
Question #1 :What is TestNG?
TestNG is a testing framework for the Java programming language created by Cédric Beust and inspired by JUnit and NUnit. The design goal of TestNG is to cover a wider range of test categories: unit, functional, end-to-end, integration, etc., with more powerful and easy-to-use functionalities
Question #2 : Advantages of TestNG?
- Annotations.15 Best Practices and Strategies for Test AutomationAPI Testing : The Definitive Guide in 2019How to do Local testing and what is it?Cross Browser Testing :Ultimate Guide in 201915 Best Practices and Strategies for Test AutomationAPI Testing : The Definitive Guide in 2019
- Run your tests in arbitrarily big thread pools with various policies available (all methods in their own thread, one thread per test class, etc…).
- Test that your code is multithread safe.
- Flexible test configuration.
- Support for data-driven testing (with @DataProvider).
- Support for parameters.
Question #3 : Annotations of TestNG?
- @BeforeTest
- @AfterTest
- @BeforeClass
- @AfterClass
- @BeforeMethod
- @AfterMethod
- @BeforeSuite
- @AfterSuite
- @BeforeGroups
- @AfterGroups
- @Test
Question #4 : What is Testng.xml file?
- Testng.xml file allows to include or exclude the execution of test methods and test groups
- It allows to pass parameters to the test cases
- Allows to add group dependencies
- Allows to add priorities to the test cases
- Allows to configure parallel execution of test cases
- Allows to parameterize the test cases
Question #5 : How to Pass Parameter Through Testng.xml File to a Test Case?
public class ParameterizedTest { @Test @Parameters("browser") public void parameterizedTest(String browser){ if(browser.equals("firefox")){ System.out.println("Open Firefox Driver"); } else if(browser.equals("chrome")) { System.out.println("Open Chrome Driver"); } } }
<parameter name=”browser” value=”firefox”/>
Question # 6: List some TestNG Assert and list out common TestNG Assertions
- assertEqual(String actual,String expected)
- assertEqual(String actual,String expected, String message)
- assertEquals(boolean actual,boolean expected)
- assertTrue(condition)
- assertTrue(condition, message)
- assertFalse(condition)
- assertFalse(condition, message)
Question # 7: What is Soft Assert in TestNG?
Soft Assert does not throw an exception when an assert fails and would continue with the next step after the assert statement.
import org.testng.asserts.SoftAssert; public class SoftAssertion { @Test public void softAssert(){ SoftAssert softAssertion= new SoftAssert(); System.out.println("softAssert Method Was Started"); softAssertion.assertTrue(false); System.out.println("softAssert Method Was Executed"); }
Question # 8: What is Hard Assert in TestNG?
Hard Assert throws an AssertException immediately when an assert statement fails and test suite continues with next @Test
public class HardAssertion { public void hardAssert(){ System.out.println("hardAssert Method Was Started"); Assert.assertTrue(false); System.out.println("hardAssert Method Was Executed"); }
Question # 9: How to create Group of Groups in TestNG?
<groups> <define name="all"> <include name="smokeTest"/> <include name="functionalTest"/> </define> <run> <include name="all" /> </run> </groups>
Question # 10: How to set test case priority in TestNG?
package TestNG; import org.testng.annotations.*; public class PriorityTestCase{ @Test(priority=0) public void testCase1() { system.out.println("Test Case 1"); } @Test(priority=1) public void testCase2() { system.out.println("Test Case 2"); } }
Where is the article?
check now