简体   繁体   English

无法使用TestNG,Gradle和Android Studio并行运行测试

[英]Unable to run tests in parallel using TestNG, gradle and android studio

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. 我正在尝试使用TestNG 6.13.1并行运行以下2个测试,并从Android Studio 3.0项目中进行gradle。

Here is my testng.xml file 这是我的testng.xml文件

<?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 我正在尝试使用在以下位置记录的Gradle TestNG选项: https ://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/testng/TestNGOptions.html gradle测试API文档可以在以下位置找到: 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 { 我正在运行build.gradle文件任务中指定的实际任务{

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 我正在使用以下命令从Windows终端运行上述任务

gradlew real testinglibrary:testDebugUnitTest

With these settings, it runs the same 'HealthCheck Test' in 2 parallel threads. 通过这些设置,它将在2个并行线程中运行相同的“ HealthCheck测试”。 Hence it duplicates the running of 1st test found. 因此,它重复了发现的第一个测试的运行。 After that it runs SignIn Test in single thread. 之后,它将在单线程中运行SignIn Test。 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. 理想情况下,它应同时在两个线程中同时启动HealthCheck测试和SignIn测试,并且不应重复运行HealthCheck测试。 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. 它似乎也没有从testng.xml读取线程计数,这就是为什么我在上面的testng.xml文件中将其注释掉了。 I also commented out //maxParallelForks = 2 from build.gradle as it was NOT doing any parallelization of tests. 我还从build.gradle中注释掉了// maxParallelForks = 2,因为它没有进行任何测试并行化。 It looks like testng api within gradle is buggy. gradle中的testng api似乎有问题。

Please guide how to achieve parallelization of my appium integration tests using TestNG, gradle (not maven) from an android studio test automation framework. 请指导如何使用Android Studio测试自动化框架中的TestNG,gradle(而非Maven)实现我的Appium集成测试的并行化。

Try to remove 尝试删除

setParallel('tests') setThreadCount(2) and use corresponding settings in xml only setParallel('tests') setThreadCount(2)并仅在xml中使用相应的设置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM