Wanting to write some tests for my application, I came across Android testing pages . After quite a long reading, it quickly became apparent that the only thing I could break out of it was information on how to test the interface / actions. I really want to test my logic just by ant test , preferably even without a device. At this point, I should mention that I am not using Eclipse, and it’s pretty sad that 99% of the Java resources on Android suggest that people do this.
In any case, trying to achieve anything at all, I played with the textbook as much as I could. He asks that the tests directory is at the same level as src . Of course, even if each of their pages assumes that the test project is a completely separate object. While in the top-level project directory, I ran android create test-project -m /path/to/my/project/ -n MyProjectTest -p tests . It is worth noting that they are very inconsistent with the way they want things to be set up as can be seen on this issue . When visiting the directory, I see the default test file. Here is where the problems begin.
As far as I understand, testing is performed as follows: build application, install; go for tests, build tests, install; run tests from the test catalog with ant test or run them directly with adb shell am instrument . This works great. However, I have no desire to test activity, but only logic (which does not have access to any representations / actions).
Changing the default test for the AndroidTestClass extension seems to have worked for a while. The tests ran, but there were caveats: cleaning the tests with ant clean also cleared the project directory ( ../tests ), so it took forever to create tests in a clean environment (which is necessary because ant debug seems awful to detect changes), but it worked and I was happy.
A little later, I get java.lang.VerifyError only in my test class. By breaking down on Google and folding around, it came down to something wrong with external libraries or something wrong with my course. I do not use external .jar , so it is probably my way.
Anyway, here's my question: what is the logic of the “Right Way” to unit test in Android apps with JUnit? I can not find any resources about this: all resources are intended either for testing parts of the user interface, or for unit testing of ordinary applications.
How can I unit test use only my logic? You do not even need to start the device for this, given that I do not need to use any parts of Android. Where can I post tests? What do I need to change to run ant test in my project directory to run them?