This may turn into a design for a gomobile test subcommand, but for now I'm writing down some notes on what I've been thinking about this topic, as I have a tendency to forget parts of this story when I switch work.
Current and potential testing systems for app programmers:
go test runs unit tests on the host. Works today. Fast, portable, and friendly to development.
gomobile test same UI as go test but they run on device. Can this be made easy to configure? (Provisioning issues on iOS, app permission issues on Android, or they would run via adb shell which rules out GUI tests.) Is this useful?
GUI tests. Right now x/mobile/app/app_test.go has some primitive GUI tests driven by the host. Can these be run on-device as part of gomobile test?
Go libraries used by android apps:
go test runs unit tests on the host.
gomobile test runs tests on the device. Same discussion as above.
Integration tests. As Go is the library, these have to be driven by the primary app environment, Android Studio, Xcode, etc. (For example, x/mobile/bind tests do this with gradle from the Android SDK.)
If we created a gomobile test mode, it would be built out of the go_darwin_arm_exec and go_android_arm_exec scripts used to run unit tests from the standard library. These are tricky to setup (in particular the ios-deploy dependency) and very tricky to debug. It i not clear we could make that easier with the gomobile tool.
So it’s not clear yet that it is worth building gomobile test, but a worthwhile first experiment would be rewriting x/mobile/app/app_test.go to be a unit test running under an .apk. If that is possible, the second step would be to rewrite go_android_arm_exec so that it builds app packages like go_darwin_arm_exec. In some ways it is easier to install and start an app on Android than it is on iOS, but extracting stdio usefully on a device without root (most development devices) is a bit of work.
The text was updated successfully, but these errors were encountered:
For the second case (Go libraries used by apps) I would not recommend having a gomobile test option, based on my personal experience. For Go code used by native code, if a test is not written in the native language it will not exercise the boundary between Go and the native language. If we don't need to exercise this boundary, then a pure go test is sufficient. If not we will need tests written in the native language. There are a number of existing test frameworks which are geared to doing this. They fit well within the development workflow for those languages and I don't see anything gained by adding a third tool. Hope this is useful!