21. How To Ignore A Test Case In Testng?
Answer: To ignore the test case we use the parameter enabled = false to the @Test annotation.
@Test(enabled = false)
22. How Testng Allows To State Dependencies?
Answer: TestNG allows two ways to declare the dependencies.
Using attributes dependsOnMethods in @Test annotations
Using attributes dependsOnGroups in @Test annotations.
23. What Are The Different Ways To Produce Reports For Testng Results?
TestNG offers two ways to produce a report:
Listeners implement the interface org.testng.ITestListener and are notified in real time of when a test starts, passes, fails, etc…
Reporters implement the interface org.testng.IReporter and are notified when all the suites have been run by TestNG. The IReporter instance receives a list of objects that describe the entire test run.
24. What Is The Use Of @listener Annotation In Testng?
Answer: TestNG listeners are used to configure reports and logging. One of the most widely used listeners in testNG is ITestListener interface. It has methods like onTestStart, onTestSuccess, onTestFailure, onTestSkipped etc. We should implement this interface creating a listener class of our own. Next we should add the listeners annotation (@Listeners) in the Class which was created.
25. How To Write Regular Expression In Testng.xml File To Search @test Methods Containing “smoke” Keyword.?
Answer: Regular expression to find @Test methods containing keyword “smoke” is as mentioned below.
<methods>
<include name=”.*smoke.*”/>
</methods>
26. What Is The Time Unit We Specify In Test Suites And Test Cases?
Answer: We specify the time unit in test suites and test cases is in milliseconds.
27. List Out Various Ways In Which Testng Can Be Invoked?
Answer: TestNG can be invoked in the following ways:
Using Eclipse IDE
Using ant build tool
Using Maven
From the command line
Using IntelliJ’s IDEA
28. What Is The Use Of @test(invocationcount=x)?
Answer: The invocationcount attribute tells how many times TestNG should run a test method
@Test(invocationCount = 10)
public void testCase1(){
In this example, the method testCase1 will be invoked ten times.
29. What Is The Use Of @test(threadpoolsize=x)?
Answer: The threadPoolSize attribute tells to form a thread pool to run the test method through multiple threads.
Note: This attribute is ignored if invocationCount is not specified
@Test(threadPoolSize = 3, <code class=”plain”>invocationCount = </code><code class=”value”>10</code>)
public void testCase1(){
In this example, the method testCase1 will be invoked from three different threads.
30. What Does The Test Timeout Mean In Testng?
Answer: The maximum number of milliseconds a test case should take.
@Test(threadPoolSize = 3, invocationCount = 10, timeOut = 10000)
public void testCase1(){
In this example, the function testCase1 will be invoked ten times from three different threads. Additionally, a time-out of ten seconds guarantees that none of the threads will block on this thread forever.