Issue
Whenever I launch a unit test "from the margin menu" (see screenshot), that does not have any Android dependencies, Android Studio compiles my whole app only to run one primitive assert.
Is it the intended behaviour that my app needs to fully compile? I was expecting that unit tests are extremely fast and compile only those classes mentioned in the test and their dependent classes are to be compiled for unit testing.
Moreover, if I add any Android class, e.g. Application or AppCompatActivity, to the test it will still complete successfully. Every article about testing on Android says that it's impossible to run a unit test that depends on any Android library.
Solution
Gradle projects are usually structured to have a main source set and a test source set. They are compiled separately and test is configured to depend on main. All Gradle knows is that it needs main if it is supposed to run test. Therefore it compiles all of main before compiling test. You can see that in action when compiling test if you look at the "build" panel. In fact, if any class in main has syntax errors it will not even try to compile test even if that class is not needed for test.
Answered By - EricSchaefer

0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.