Found 136 Articles for TestNG

How to Limiting the Number of Parallel Tests with ThreadCount in TestNG?

Ashish Anand
Updated on 18-Aug-2023 11:48:45

227 Views

TestNG supports multi−threading i.e. a @Test methods can be invoked parallelly. A test or multiple test methods can be invoked from multiple threads. Therefore, multiVthread is useful if @Test methods need to be run asynchronously in parallel. Multi−threading can be achieved by using keyword − thread−count = at Testng.xml. Thread count is basically number of instances running to execute multiple tests simultaneously or parallelly. The attribute thread−count allows the user to specify how many threads should be run for this execution. In this example, 5 @Test method will execute in parallel from 5 threads. In this article, we will ... Read More

Junit vs TestNG vs Mockito

Ashish Anand
Updated on 18-Aug-2023 11:45:57

375 Views

JUnit and TestNG are the most popular testing frameworks for Java applications. Both frameworks are easy to use. So, when it comes to choose the testing framework for your application, it’s better to have a high−level idea of what features are present in one or the other and then take the informed decision based on your project requirements. In this article, we will see JUnit vs TestNG. Junit vs TestNG JUnit current version is 5.7.1 and it’s still evolving and working on to include more features. TestNG current version is 7.4.0 and it’s mature and features rich. Following table compares ... Read More

How to Invoke Junit Test Cases in TestNG?

Ashish Anand
Updated on 18-Aug-2023 11:38:01

126 Views

TestNG can automatically recognize and run JUnit tests, so that you can use TestNG as a runner for all your existing tests and write new tests using TestNG. All you must do is to put JUnit library on the TestNG classpath, so it can find and use JUnit classes, change your test runner from JUnit to TestNG in Ant, and then run TestNG in "mixed" mode. This way, you can have all your tests in the same project, even in the same package, and start using TestNG. This approach also allows you to convert your existing JUnit tests to TestNG ... Read More

How to write a TestNG Listener that can List all Groups of a Test Method?

Ashish Anand
Updated on 18-Aug-2023 11:36:03

89 Views

A TestNG class can have different tests like test1, test2, test3 etc. and these tests can be grouped based on different groups like unit, integration or both or any bug number. User may want to run the @Test method based on groups. And, it is always convenient to know which test method belongs to which group so that these details can be included into report. TestNG supports multiple ways to get group name at run time such as injection dependency and Listeners are most popular. Even in Listeners it can be achieved using ITestListener or IInvokedMethodListener. In this article, let’s ... Read More

How to Write a TestNG Listener that can Fetch Name of Executing Test Method?

Ashish Anand
Updated on 18-Aug-2023 11:23:48

107 Views

A TestNG class can have different tests like test1, test2, test3 etc. and these tests can be grouped based on different groups like unit, integration or both or any bug number. User may want to run the @Test method based on groups. And, it is always convenient to know which test method belongs to which group so that these details can be included into report. TestNG supports multiple ways to get test name at run time such as injection dependency and Listeners are most popular. Even in Listeners it can be achieved using ITestListener or IInvokedMethodListener. In this article, let’s ... Read More

How to Stop Suite Execution after First Failure in TestNG?

Ashish Anand
Updated on 18-Aug-2023 11:17:10

144 Views

A TestNG class can have different tests like test1, test2, test3 etc. There could be some failure while running the test suite and user may get failures in between of @Test methods. Once a test method gets failed, it skip remaining code of the @Test method and moves to the next @Test method. However, user may want to skip remaining all @Test methods after getting 1st failure. There are 2 most popular solution for such use cases: Write dependsOnMethods annotation – But this solution works only if user knows exact dependent method/s otherwise in large suite it would be ... Read More

How to use Selenium with TestNG?

Ashish Anand
Updated on 18-Aug-2023 11:08:30

116 Views

TestNG is a powerful testing framework, an enhanced version of JUnit which was in use for a long time before TestNG came into existence. NG stands for 'Next Generation'. TestNG framework provides the following features − Annotations help us organize the tests easily. Flexible test configuration. Test cases can be grouped more easily. Parallelization of tests can be achieved using TestNG. Support for data−driven testing. Inbuilt reporting. Selenium allows to interact with webpages. It is an interface not a testing framework. To run any test or code only in selenium we must use java main method. TestNG provides ... Read More

What are Best Practices of Selenium Web Test Automation Framework?

Ashish Anand
Updated on 18-Aug-2023 11:06:38

82 Views

The best practices for Selenium web test automation framework are listed below − Use of dynamic waits like implicit wait and explicit wait instead of using Thread.sleep() in the framework to handle sync issues in the application. Usage of Page Object Model framework design to segregate the test scripts from the locators. In case of changes in the web−element properties, test scripts need not be modified only the locators undergo change. Usage of Behaviour Driven Development framework. This allows the participation of all members in the agile team to participate in product development. Encourage testing to start from very ... Read More

How to do Selenium Testing on different Browsers using TestNG?

Ashish Anand
Updated on 18-Aug-2023 11:04:57

197 Views

TestNG is a powerful testing framework, an enhanced version of JUnit which was in use for a long time before TestNG came into existence. NG stands for 'Next Generation'. A website should be tested across multiple browsers like IE, Chrome, Firefox, Safari to validate the compatibility of website and functionality. Since the HTML, CSS and java scripts are unique across all browsers, it is always recommended to do cross browser testing to ensure the compatibility of website. Selenium supports cross browser testing so does the TestNG. In this article, we will analyse how to perform cross browser testing in Selenium ... Read More

How to Run a testng.xml File From Batch for a Maven Project?

Ashish Anand
Updated on 18-Aug-2023 10:58:43

878 Views

TestNG is a testing framework and can use Maven as build tool. It helps to maintain dependencies and their version at one place in pom.xml Maven provides flexibility to run using surefire plugin. If a user has multiple testng.xml files (please note one testng files contains only one test suite), he/she may run the specific suite based on the requirement. Maven provides the flexibility to define suiteXMLFiles as variable and pass the value of variable at run time using command line. And, at the same time user can create batch file using this command and run it as batch file. ... Read More

Advertisements