there are two main types of testsyou can add to your android project, unit tests and connected tests. the primary distinction between the two, is that unit tests run on a regularjava vm on your computer. and connected tests run onan android device or emulator.
Android unit testing, in general,you should use unit tests for testing generic,non-android related classes. in fact, since unite tests are runagainst a mock android stk implementation, any code thatcalls the android api will fail.
in this case, you should either usea mocking framework like makido, to mock the appropriate android dependencies,or use a connected test instead. additionally, you can configurethe testing options in your gradle built script, to construct the mock androidimplementation to return default values, rather than throw an error. in any case, it's up to you as a developer to decidehow to best write your tests, and how to structure your code in sucha way as to make testing easier. connected tests should be reserved for
testing logic that dependon android api's, or for more high level testing likeintegration and functional tests. remember, connected tests are packagedas an apk that will be installed on an android device or emulator. so there's typically more overheadinvolved in their execution. both unit tests and connected tests havetheir own source sets, named test and android test respectively.
the notion of variantsextends to tests as well. allowing you to write tests specificto your build type of product flavor.
the naming conventions for these sourcesets follow the same pattern as for application code, except forthe test or android test suffix.