Hello, I am a huge fan of Maven when it comes to automation project. But i recently joined in a team where Gradle is used companywide. What is Gradle? Gradle is an open-source build automation system that builds upon the concepts of Apache Ant and Apache Maven and introduces a Groovy-based domain-specific language (DSL) instead of the XML form used by Apache Maven for declaring the project configuration.

As far as I see Gradle does what Maven does when it comes to configuration and execution Here might be some advantages or disadvantages but I haven’t gotten into deeper parts of it. So I am going tell my story and some tips and tricks based on my experience.


Adding a dependency into your project is a straightforward process. Just go to https://mvnrepository.com/ and select Gradle tab. You’ll find your dependency. Add that to your build.gradle file in a parent folder.

There are two ways of scoping when it comes to adding a dependency to your project:

  • Compile: You’ll be able to use those kinds of libraries in your main and test folders.
  • testCompile: You’ll be able to use those kinds of libraries only in test folders.

How to Add TestNG XML into Gradle File

Open your build.gradle file and add those line at the end of it.

Running Specific Group of Tests via CLI

There are times we need to group our tests into logical groups like smoke, regression and execute them.

First, you need to group your tests by using TestNG’s default grouping feature. You can find an example in that link>http://www.swtestacademy.com/testng-tutorial/

Here’s a sample also:

Then we create a new Gradle task in build.gradle file as below.

As you see, we don’t need to do any changes in our XML file.

Finally, we execute “gradle smokeTests” command via CLI and see the results like a charm. Now the only test with smoke groups will start.