android / testing-samples

A collection of samples demonstrating different frameworks and techniques for automated testing
Apache License 2.0
9.21k stars 3.62k forks source link

Gradle Managed Device not able to run with Orchestrator #505

Closed Johnson-OpNet closed 10 months ago

Johnson-OpNet commented 10 months ago

I am currently trying to use Gradle Managed Devices to replace instrumented tests, after completing the official setup steps, the execution fails with the log message Starting 0 tests on pixel2Api29 I found that it's because of ANDROIDX_TEST_ORCHESTRATOR, can these 2 utils goes together? If not, how can I remove all shared state from your device's CPU and memory after each test and how to isolate crashes if I run the test by GMD? Thanks in advance.

My current settings

defaultConfig {
     testInstrumentationRunner "com.android.CustomTestRunner"
     testInstrumentationRunnerArguments clearPackageData: 'true'
}

testOptions {
        execution 'ANDROIDX_TEST_ORCHESTRATOR'
        animationsDisabled = true
        unitTests.returnDefaultValues = true

        managedDevices {
            localDevices {
                pixel2api29 {
                    device = "Pixel 2"
                    apiLevel = 29
                    systemImageSource = "aosp"
                }
            }
        }
    }

gradle: https\://services.gradle.org/distributions/gradle-8.0-all.zip AGP: com.android.tools.build:gradle:8.1.4 orchestrator: androidx.test:orchestrator:1.4.2

brettchabot commented 10 months ago

GMD should be able to work with orchestrator. See https://github.com/android/android-test/blob/main/gradle-tests/orchestrator/build.gradle which does this.

If you're having issues with GMD, I'd recommend filing bugs under the gradle component listed here https://source.android.com/docs/setup/contribute/report-bugs

EgorUdev commented 6 months ago

@Johnson-OpNet hi! Have you solved the issue? I faced with same issue at the same configuration but can not find the solution

utzcoz commented 6 months ago

I think you also need use androidTestUtil to add orchestrator to your dependencies. At least, I can run it locally with orchestrator + GMD.

EgorUdev commented 6 months ago

@utzcoz hi! I did not get it, sorry. What do you mean use androidTestUtil?

brettchabot commented 6 months ago

Declare your dependency like this: 'androidTestUtil androidx.test:orchestrator:1.4.2'

Please see the example I gave above for more details. Specifically this line https://github.com/android/android-test/blob/7071e3175d7262f2dabc6981d632c44339b99792/gradle-tests/orchestrator/build.gradle#L53

EgorUdev commented 6 months ago

I tried both variants androidTestUtil 'androidx.test:orchestrator:1.4.2' in app build.gradle and androidTestUtil libs.testOrchestrator in app build.gradle which is linked to testOrchestrator = { group = "androidx.test", name = "orchestrator", version.ref = "testOrchestrator" } in settings.gradle

Both variant leads to Starting 0 tests

brettchabot commented 6 months ago

Would it be possible to narrow down the cause of the failure by starting from the working sample I provided, and incrementally introducing changes until you get a failure?

utzcoz commented 6 months ago

@EgorUdev Another occasion that I have faced is that: your tests code has compiling errors or other code related errors, and the compilation failed that causes "Starting 0 tests". So you can check whether your test suite can work with ./gradlew cAT without orchestrator.