TestNG Top 10 Interview Questions with Answers
1. What is the sequence of execution of the annotations in TestNG?
Ans : annotations in order from
Before Suite method
Before Test method
Before Class method
Before Method
After Method
After Class method
After Test method
2. Can you arrange the below <testng.xml> tags from parent to child?
<test>
<suite>
<class>
<methods>
<classes>
Ans : Correct order
<suite>
<test>
<classes>
<class>
<methods>
3. How to run test cases in parallel using TestNG?
Ans : parallel = tests/methods/classes
4. In TestNG I have some test’s Test1-Test2-Test3-Test4- Test5. I want to run my execution order is Test5-Test1-Test3-Test2-Test4. How do you set the execution order?
Ans : By priority
@Test (priority=1) in Test5
@Test (priority=2) in Test1 and continues...
5. If a test method failed, then its dependent method will
Ans : Never execute
6. If no priority is set for the test methods then the execution order will be?
Ans : Based on the Alphabetical naming conventions of the test methods
Example code:
import org.testng.annotations.Test;
public class TestNG_Priority_Annotations {
@Test
public void c_method(){
System.out.println("I'm in method C");
}
@Test
public void b_method(){
System.out.println("I'm in method B");
}
@Test
public void a_method(){
System.out.println("I'm in method A");
}
@Test
public void e_method(){
System.out.println("I'm in method E");
}
@Test
public void d_method(){
System.out.println("I'm in method D");
}
}
Output
I'm in method A
I'm in method B
I'm in method C
I'm in method D
I'm in method E
7. What is difference between Hard assert and soft assert.
Ans :
Soft Assert collects errors during @Test. Soft Assert does not throw an exception when an assert fails and would continue with the next step after the assert statement.
Hard Assert throws an AssertException immediately when an assert statement fails and test suite continues with next @Test
8. How to ignore a test in testng.
Ans :
To ignore the test case we use the parameter enabled = false to the @Test annotation.
@Test(enabled = false)
9. Can you specify any 6 assertions of TestNG to be used
1- assertEquals
2- assertNotEquals
3- assertTrue
4- assertFalse
5- assertNull
6- assertNotNull
10. What runs exactly before and after @Test annotation
answer choices
@BeforeMethod and @AfterMethod
@BeforeTest and @AfterTest
@BeforeClass and @AfterClass
Ans : @BeforeTest and @AfterTest
https://www.knowlathon.com/project-management/prince2-foundation-and-practitioner-bangalore/
ReplyDeletehttps://www.knowlathon.com/project-management/prince2-agile-foundation-and-practitioner/
https://www.knowlathon.com/project-management/prince2-foundation-training/
https://www.knowlathon.com/project-management/prince2-practitioner-chennai/
https://www.knowlathon.com/project-management/prince2-practitioner-pune/
https://www.knowlathon.com/project-management/prince2-practitioner-delhi/
https://www.knowlathon.com/project-management/prince2-practitioner-hyderabad/
https://www.knowlathon.com/project-management/prince2-agile-foundation-dubai/
https://www.knowlathon.com/it-service-management-and-excellence/itil4-managing-professional-transition/