开发者

Trying to understand android testing

开发者 https://www.devze.com 2023-03-07 10:27 出处:网络
I\'m a long time Java developer with many years of Java EE, Ant, Maven, unit testing, mocks, et开发者_开发问答c. I\'m currently using gradle to build android apps and am looking at unit testing them.

I'm a long time Java developer with many years of Java EE, Ant, Maven, unit testing, mocks, et开发者_开发问答c. I'm currently using gradle to build android apps and am looking at unit testing them. And it's got me tearing my hair out!

My reading indicates that to test an app, I have to create another app inside it in a test directory. But I'm not sure how this embedded app can see the main apps classes. I presume that google came up with this because of something to do with the manifests which are different. I'm not sure why.

Without doing this embedded app system, I've been able to get unit tests to run by including the test classes with the main classes in the APK, adding the instrumentation declarations to the manifest, deploying it and running the test runners. But I don't want to be compiling test classes with app classes and including all the dependencies so that's not really an option and I'm not really sure of the effects of the changes to the manifest as I cannot find any documentation about the effects.

None of this is understood by gradle which follows the maven system of building. Also note that the android way seems to be that the embedded sub-project (test) is dependant on the main parent project, something that is totally contray to gradle and maven.

Another option seems to be separate the test project so that it's completely outside the app project. But really, I'd like to use a similar convention to maven and simply have tests in a separate directory, along with the manifest in test resources.

Has anyone managed to get testing on the emulators running unit tests following a more maven like directory structure?


You can try Robotium. It provides lots of features for a better testcase. You can have a look at it here.


Do you have to run the unit tests in the emulator? Isn't that too slow? I've been using robolectric ( http://pivotal.github.com/robolectric/ ) which creates shadow objects that work similar to mocks. I use progaurd ( http://proguard.sourceforge.net/ ) to strip out the tests for the release build.

0

精彩评论

暂无评论...
验证码 换一张
取 消