Found 206 Articles for Dynamic Programming

How does TestNG invoke a test method using multiple threads?

Ashish Anand
Updated on 09-Mar-2022 11:44:46

3K+ Views

TestNG supports multi-threading, i.e., a @Test method can be invoked multiple times in parallel. A test method should be invoked from multiple threads so that multiple invocation is also required. If we want to run a single @Test at multi-thread, it is of no use. Therefore, multi-thread is useful if a @Test method needs to be run multiple times asynchronously.Multi-threading can be achieved by using the keyword threadPoolSize = at @Test. However, to invoke a method multiple times, another keyword invocationCount =  is required. Combining these two keywords, we can achieve multi-threading. For example, @Test(threadPoolSize=5, invocationCount = 10)In this example, ... Read More

How to disable a TestNG test based on a condition?

Ashish Anand
Updated on 09-Mar-2022 11:43:08

1K+ Views

TestNG supports multiple ways to skip or ignore a @Test execution. Based on the requirement, a user can skip a complete test without executing it at all or skip a test based on a specific condition. If the condition meets at the time of execution, it skips the remaining code in the test.Following are the ways to skip the @Test execution −Use the parameter enabled=false at @Test. By default, this parameter is set as True.Use throw new SkipException(String message) to skip a test.Conditional Skip – The user can have a condition check. If the condition is met, it will throw ... Read More

How to get the result status from TestNG in @AfterMethod?

Ashish Anand
Updated on 09-Mar-2022 11:40:01

2K+ Views

TestNG supports native dependency injection. It allows to declare additional parameters in methods. At the runtime, TestNG automatically fills these parameters with the right values. Here is a list of some native dependencies in TestNG:ITestContextXmlTestMethodITestResultYou can use these dependencies to get the execution status of a test in TestNG.Usually, @AfterMethod supports all these native dependencies and the test status could be either Success, Failure or Skip.TestNG supports the following test status that can be retrieved by calling the function at the right place.org.testng.ITestResultpublic static final intFAILURE2public static final intSKIP3public static final intSTARTED16public static final intSUCCESS1public static final intSUCCESS_PERCENTAGE_FAILURE4In this article, ... Read More

How to make TestNG print a detailed message about a failure?

Ashish Anand
Updated on 09-Mar-2022 11:28:15

683 Views

TestNG supports a lot of assertions. It has the org.testng.Assert class that extends the Java object class java.lang.object.Whenever there is a failure, a user would want to get a detailed failure report in order to perform a root cause analysis. But, sometimes the displayed failure information is not sufficient and sometimes the user is supplied with the same type of failure information repeated every time. These kinds of issues can be handled in TestNG using the keyword verbose ="".TestNG supports verbose and allows the user to pass a value based on the extent of failure information they want to see. ... Read More

How to execute a single test from a large testing suite using TestNG.xml?

Ashish Anand
Updated on 09-Mar-2022 11:23:54

9K+ Views

testNG.xml is very flexible and it can work as a harness file to execute the test cases. It keeps the development and execution separate from each other. A user can develop "N" number of test cases in testNG but can run a limited number of test methods based on the configuration in testNG.xml.In this article, let's see how to run only one test method from a large TestNG suite.To run only one test method, we will use the 'include' keyword from TestNG. In testNG.xml, first we will define the class name where the method is present and after that mention ... Read More

How to run a specific group of tests in TestNG from command line?

Ashish Anand
Updated on 09-Mar-2022 11:21:05

2K+ Views

Group test is a new innovative feature in TestNG, which doesn't exist in JUnit framework. It permits you to dispatch methods into proper portions and perform sophisticated groupings of test methods.Not only can you declare those methods that belong to groups, but you can also specify groups that contain other groups. Then, TestNG can be invoked and asked to include a certain set of groups (or regular expressions), while excluding another set.Group tests provide maximum flexibility in how you partition your tests. You do not have to recompile anything if you want to run two different sets of tests back ... Read More

How to turn off TestNG's default reporters programmatically?

Ashish Anand
Updated on 09-Mar-2022 11:14:00

345 Views

TestNG allows to run the test suites from IntelliJ IDE as well as from the command line. When user runs the testNG.xml either from an IDE or the command line, TestNG generates a default report. It saves all the reports and respective HTML files in the Project->test-output folder. If this folder does not exist, then TestNG creates one.To disable the default reports programmatically, TestNG should be run through the command line (cmd).Following are the prerequisites to run the test suites from the command line −testNG.xml file should be created to define the test suites and testing classes to execute.All the ... Read More

How to get a list of all the test methods in a TestNG class?

Ashish Anand
Updated on 09-Mar-2022 11:04:30

1K+ Views

TestNG supports native dependency injection. It allows to declare additional parameters in methods. At the runtime, TestNG automatically fills these parameters with the right values. Here is a list of some native dependencies in TestNG:ITestContextXmlTestMethodITestResultThese dependencies help to retrieve the names of test methods depending on where they are called. If the user wants to retrieve the names of all the test methods that are going to be executed in a class, the best place is @BeforeClass or @AfterClass. @BeforeClass and @AfterClass support ITestContext and XmlTest.The following table shows the full access of these dependencies −AnnotationITestContextXmlTestMethodITestResultBeforeSuiteYesNoNoNoBeforeTestYesYesNoNoBeforeGroupsYesYesNoNoBeforeClassYesYesNoNoBeforeMethodYesYesYesYesTestYesNoNoNoAfterMethodYesYesYesYesAfterClassYesYesNoNoAfterGroupsYesYesNoNoAfterTestYesYesNoNoAfterSuiteYesNoNoNoIn this article, we will ... Read More

How to use TestNG SkipException?

Ashish Anand
Updated on 09-Mar-2022 10:57:10

5K+ Views

TestNG supports multiple ways to skip or ignore a @Test execution. Based on requirement, a user can skip a complete test without executing it at all or skip a test based on a specific condition. If the condition meets at the time of execution, it skips the remaining code in the test.Following are the ways to skip a @Test execution −Use the parameter enabled=false at @Test. By default, this parameter is set as True.Use throw new SkipException(String message) to skip a test.Conditional Skip − The user can have a condition check. If the condition is met, it will throw SkipException ... Read More

How to use regular expression in class path in TestNG.xml?

Ashish Anand
Updated on 09-Mar-2022 10:51:25

660 Views

testNG.xml has a format where we define all the test classes that should be executed. There is no any specific way to provide regular expression in a class in . But there are workarounds of course which are quite useful in case you want to run a specific @Test from a class. TestNG supports regular expression at include, exclude and package tags.Following are the ways in which you can use regular expression in a test class that is to be run from a test suite.Mention all the class names inside . And, inside the class, use and . ... Read More

Advertisements