Running a specific instrumentation unit test with Gradle

后端 未结 8 950
既然无缘
既然无缘 2020-11-30 04:27

Is there a way to run a specific Android instrumentation unit test using Gradle? I\'ve tried

gradle -Dtest.single=UnitTestName connectedInstrumentTest
         


        
8条回答
  •  醉酒成梦
    2020-11-30 05:18

    Using test.single appears to be deprecated. The new correct way to do this is

    ./gradlew ::test --tests 
    

    where could be something like:

    • com.example.MyTest to run all test methods in com.example.MyTest
    • *MyTest to match every method in every class whose name ends with MyTest
    • *.MyTest.myMethod to run a specific test method in class MyTest in any package

    If you have a multi-project build, make sure to give the module path before the test task; otherwise you'll get a misleading error message when it searches for your test pattern in every subproject.

    None of this is documented on the Gradle site anywhere I could find it.

提交回复
热议问题