kl. 18:49:07 UTC+2 torsdag 4. april 2013 skrev Xavier Ducrohet følgende:
Are you writing custom code in your build.gradle to manually install, run tests and uninstall apks? I'll have to add the ability to add a serial number to the task. There's nothing right now to deal with this.
That's right. A 'deviceId' commandline property also proved necessary, to be able to choose which device to use, in addition to the startEmulator/stopEmulator tasks.
It would've been prettier to modify your Android plugin directly, but my customer didn't like that approach.
I haven't looked at figuring out how to deal with build servers launching emulators in parallel yet.
It's something I want to look at. One thing I've been thinking about is relying on the fact that emulators can be queried for their AVD names so we could just use this to make sure the test apks are deployed to the right emulator.
This would work in combination with the ability to declare AVDs in build.gradle and have the test runner deal with launching the AVD, installing, running the test, uninstalling and closing the emulator.
Sounds good!
The build script would create the AVD with a unique, known name, like 'test-<UUID>' and query for that name?
Maybe if the 'deviceId' property (or similar) was given on the commandline, the tests would run on the specified (physical or emulator) device? E.g. 'gradle -PdeviceId=emulator-5556 clean assemble instrumentTest'
Perhaps starting the emulator before running the instrument/uiautomator-tests could be the default behaviour when the 'deviceId' property is not specified.
I did it slightly differently:
1 Deleted and re-created the emulator during startEmulator with 'android create' to have a known starting point for the tests
2 Found the serial of this emulator by setting a property at create time,
emu.id to a known, unique value, and querying all emulators for it in loop until the matching
emu.id was found
3 Waited for the emulator to boot, before running the next task, by waiting for the property "init.svc.bootanim" to become "stopped"
This last step (or something equivalent) is probably necessary in your approach too.