Skip to main content

How to invoke test for specific testng.xml using gradle

We know how to execute the whole set of test suite using gradle, here in this blog we show you how do we call specific set of tests with gradle which we have segregated tests based on multiple testng.xml files?

Solution: Add below snippet at end of build.gradle file, we will define suites with project property function, and we will pass these suite objects to useTestNG function by validating user defined suite name with passed suite object.

=====================================
def suite1=project.hasProperty("suite1")

def suite2=project.hasProperty("suite2")

def suite3=project.hasProperty("suite3")

test {

    testLogging {

        exceptionFormat = 'full'

        events = ["passed", "failed", "skipped"]

        showStandardStreams = true

    }

    useTestNG() {

/*This XML file is to execute first test suite*/

    if(project.hasProperty("suite1")) {

        suites "testng1.xml"

        }

/*This XML file is to execute second test suite*/

    if(project.hasProperty("suite2")) {

        suites "testng2.xml"

        }

/*This XML file is to execute third test suite*/

    if(project.hasProperty("suite3")) {

        suites "testng3.xml"

        }

    }
=======================================

When we run "gradle test -Psuite1" in command line of repo, which will only execute all the tests defined in testng1.xml file, use same for suite2(gradle test -Psuite2) and suite3(gradle test -Psuite3) and so on.

Comments

Popular posts from this blog

javamail jdk11(11.0.10 and above) needs tls upgrade from 1.1 to 1.2

ISSUE 1: Unable to send/read mails using javamail/javaxmail after you upgraded your jdk to 11.0.10 or above?  The reason is they came up with higher security level for SSL with TLS 1.2 which is dependency for latest jdk, find the solution below: Possible Exception if you used older version TLS-1.1:  javax.net.ssl.sslhandshakeexception Solution: Add below property to your existing Properties. properties.put("mail.imaps.ssl.protocols","TLSv1.2");(IMAP used to read mail) properties.put("mail.smtp.ssl.protocols","TLSv1.2");(SMTP used to send mail) ISSUE 2: Unable to type case Multipart to String? From jdk11(latest version) onwards multipart and string cant be type casted, so we need to use Object to store message content. Solution: for (int i = 0; i < messages.length; i++) { Message message = messages[i]; Object content = message.getContent(); if (content instanceof String) { String body = (String)content; System.out.println...

Extent report for Rest API test

Below code helps in failing or passing your Rest API test case & updating result to Extent report. Maven dependency(pom.xml): <dependency>     <groupId>com.aventstack</groupId>     <artifactId>extentreports</artifactId>     <version>4.0.9</version> </dependency> code: import com.aventstack.extentreports.ExtentReports; import com.aventstack.extentreports.reporter.ExtentHtmlReporter; import com.aventstack.extentreports.reporter.ExtentLoggerReporter; public class A{ ExtentLoggerReporter logger = new ExtentLoggerReporter("dir path to store extent result"); static ExtentReports extent; @Test public void testname(){ //Your code to capture json from get/post/put/delete API to "JSONObject jsonobjexpected" field. //your code to read actual json content from file/anywhere to "JSONObject jsonobjactual" field. try {         JSONAssert.assertEquals(jsonobjexpected.toString(...

RestAssured rest API test framework for GET & POST API json verification with Extent report

package com.resttest; import static io.restassured.RestAssured.given; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.sql.DriverManager; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.regex.Pattern; import org.apache.commons.collections.iterators.EntrySetMapIterator; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.json.JSONException; import org.json.JSONObject; import org.skyscreamer.jsonassert.JSONAssert; import org.skyscreamer.jsonassert.JSONCompareMode; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; import org.testng.Assert; import org.testng.TestNG; import org.testng.annotations.AfterTest; import org.testn...