0

I am trying to run the following 2 tests in parallel using TestNG 6.13.1 and gradle from an Android studio 3.0 project.

Here is my testng.xml file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Default test suite">
    <!--parallel="methods" thread-count="4">-->
    <listeners>
        <listener class-name="org.testng.reporters.XMLReporter"></listener>
    </listeners>
    <test  name="SignIn Test" >
        <classes>
            <class name="com.android.testinglibrary.DeviceTesting.Appium.SignInTest"/>
        </classes>
    </test>
    <test  name="HealthCheck Test" >
        <classes>
            <class name="com.android.testinglibrary.DeviceTesting.Appium.HealthCheckTest"/>
        </classes>
    </test>

</suite>

I am trying to use Gradle TestNG Options documented at: https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/testng/TestNGOptions.html The gradle test api documentation can be found at: https://docs.gradle.org/current/dsl/org.gradle.api.tasks.testing.Test.html

I am running following task which is specified in my build.gradle file task real {

description = "real"

    tasks.withType(Test) {
        useTestNG() {
            //maxParallelForks = 2
            options {
                suites 'src/test/java/com/android/testinglibrary/DeviceTesting/Appium/testng.xml'
                setParallel('tests')
                setThreadCount(2)
            }
        }
    }

}

I am running the above task from windows terminal using following command

gradlew real testinglibrary:testDebugUnitTest

With these settings, it runs the same ‘HealthCheck Test’ in 2 parallel threads. Hence it duplicates the running of 1st test found. After that it runs SignIn Test in single thread. Ideally it should start both HealthCheck Test and SignIn Test in 2 threads at the same time and should NOT duplicate the running of HealthCheck Test. It also does NOT seem to read thread-count from testng.xml and that is why I commented it out in testng.xml file above. I also commented out //maxParallelForks = 2 from build.gradle as it was NOT doing any parallelization of tests. It looks like testng api within gradle is buggy.

Please guide how to achieve parallelization of my appium integration tests using TestNG, gradle (not maven) from an android studio test automation framework.

Parin
  • 1
  • 4
  • See the same issue here https://stackoverflow.com/questions/46106378/how-to-use-existing-testng-suite-xml-file-and-set-thread-counts-programmatically – Oleksandr Kulychok Jan 10 '18 at 13:51
  • It does not seem to be the same issue. I don't want to pass the thread count parameter programmatically. For me the gradle task execution does NOT read the thread count either from testng.xml file OR from gradle command setThreadCount(#). When I manually run the testng.xml file by right clicking, it still igonres the thread count parameters and runs all tests serially. I closed a bug with Testng and opened an issue with android studio team regarding this issue. – Parin Jan 16 '18 at 21:37
  • > When I manually run the testng.xml file by right clicking, it still igonres the thread count parameters and runs all tests serially. TestNG v13 and v13.1 has a bug when threads defined in `` (already fixed in master branch, see GITHUB-1636). Workaround is to use another testng version or define thread count in `` tag. – kool79 Jan 18 '18 at 13:49
  • > For me the gradle task execution does NOT read the thread count either from testng.xml file OR from gradle command setThreadCount(#). If gradle ivokes testng via command-line (like maven) AND you provides xml file then testng will ignore almost all other parameters (thread-count etc). All settings like setThreadCount() are used ONLY to create custom in-memmory xml file, when you dont provide xml file for testng. In other words: parameters which defined (or can be defined) in xml can be overridden ONLY programmatically (except dataproviderthreadcount system property) – kool79 Jan 18 '18 at 14:03

1 Answers1

0

Try to remove

setParallel('tests') setThreadCount(2) and use corresponding settings in xml only

kool79
  • 241
  • 2
  • 6
  • As mentioned in my original post - 'It also does NOT seem to read thread-count from testng.xml and that is why I commented it out in testng.xml file above' – Parin Jan 16 '18 at 21:26