Parallelize Test for TestNG Groups
By: Sabesan Sathananthan
Tags: Selenium, Test Automation, Testng, Java, Quality Assurance

Testing

Parallelize Test for TestNG Groups

Quality management is an essential component of the Software process. Quality management concerns with ensuring that the required level of quality is achieved in a software product. It provides an independent check on the software development process. The quality management process checks the project deliverables to ensure that they are consistent with organizational standards and goals. This is my 20th article in Medium.

TestNG is an open-source automated testing framework; where NG means NextGeneration. TestNG is inspired from JUnit and NUnit. But TestNG introducing some new functionalities that make it more powerful and easier to use. Those new functionalities are Annotations, run your tests in arbitrarily big thread pools with various policies available, the test that your code is multithread safe, flexible test configuration and support for data-driven testing. TestNG is designed to cover all categories of tests: unit, functional, end-to-end, integration, etc.

‘Groups’ is an annotation of TestNG which can be used in the execution of multiple tests. We use groups in TestNG when we don’t want to define test methods separately in different classes (depending on functionality) and at the same time. We will ignore (not to execute) some test cases as if they do not exist in the code.

I would assume that most of you had known about the word “parallelize.” In testing, parallelize means simultaneously running the test cases. If you are a Quality Engineer, then you have your automated test cases, automated framework, and continuous integration, etc. lets’ assume that your test suite will take about 10 or 12 hours or maybe more than that to run. If your project manager tells that we need to do a release within 3 or 4 hours. You can’t claim that our test frame will take 10 hours to run. With the growth of test count, time will increase. Therefore, you need to parallelize. We can achieve parallelization through hardware, software, and hybrid. Here I would like to describe how to achieve parallelization in the software method.

Parallel test execution, Source: https://www.udemy.com/parallel-test-execution/landing-page/

Advantage of using parallelize test for TestNG groups.

Low cost compared to hardware parallelize

No hardware management effects

No test results merging overhead

reduce the testing time

simultaneously run two or more group of testes

When we going to do software parallelization we should consider the following factors:

Test framework should be designed and implemented to support parallel execution

Test layer should support parallel execution

Thread-safe coding

Making test class/methods independent

Execution environment configuration

You already know Test NG already has parallelization functionality. Now we can see how could we achieve a parallelize test for Test NG groups in XML suite, and this is a straightforward way.

In testing, we can use one of the following annotations which are suitable for us.

@Test(groups = { "bind", "link" })

@Test(groups = { "bind" })

@Test(groups = { "link" })

There is another method to achieve parallelization which is suggested in TestNG Official page that:

@Test( groups = { "bind" }, threadPoolSize = 3, invocationCount = 10, timeOut = 10000)

But the above two methods are not 100% align with the distributed test execution tools such as ClusterRunner and Meissa. Therefore, here it will run these test groups assigning to the threads. There is a custom implementation to achieve parallelize test for Test NG groups. Below, we can see how to achieve that. But it is now at POC level. We want to improve it. This method was a SyscoLABS (PVT) LTD innovation idea. here I share only the key Idea.

Here we are going to create a TestNG parallel executor which will read XML from the given test suite, and it will create a thread pool. We can configure the thread count, and it will assign those groups to the executor service.

Therefore our test thread is something like the below.

Here we are passing the test group, and the group will be constructed and passed to the TestNGParallelRunner. From there, the testNG will be started. Create a Group.java class like a Java class called “Class.java”.

Conclusion

In this article, I mainly focus on TestNG groups and how to parallelize TestNG groups testing. There are many ways to parallelize the testNG groups testing. Here I described only two convenient methods.

If you want to gain more knowledge, check the official documentation page or some useful tutorial pages such as Guru99 and tutorial point.