In order to run Instrumentation Tests from within Android Studio, I typically select "Android Instrumentation Tests" as the test artifact to be built, via the Build Variants window. I recently upgraded to Android Studio 2 Beta 5, and the "Test Artifact" selector is no longer visible. Where did it go? Has some other configuration taken its place?
I discovered this in the release notes for Android Studio 2.0 Preview 5: "The experimental test artifacts feature (where both unit test and instrumentation tests are enabled simultaneously in the IDE) has been improved further and is now enabled by default."
To disable the simultaneous building of unit and instrumentation tests, go here: File Menu -> Settings -> Build, Execution, Deployment -> Build Tools -> Gradle -> Experimental. Then uncheck this: "Enable all test artifacts (Unit Test and Instrumentation Test) in Android projects".
I was also disappointed to hear this when I started developing my flashlight app quite some time ago. I haven't found a solution either, except for having a development device (my phone) to test the app on.
SO I am trying to gather the point of Unit Tests in my case. Why would I test if an Android button can click or an EditText can see what I type? I just don't understand the utility of implementing these tedious tests
if this above method passed, which all my activities run in onCreate, then I know the app works. A unit test of this would be a redundant time-consuming thing to create. Time-consuming because I am not familiar with all the methods in the jUnit and Android testing framework.
So, long story short, what's the point? Is there a particular way I should be thinking about these tests? All examples and tutorials I've seen so far only talk about the simplest examples, for the sake of brevity, but I cannot think of any practical uses for unit tests in a predominately client-server app.
Unit tests really shine when you need lots of business logic to your project. In this case you probably want to divide your application into multiple layers (say, 3-tier architecture) to, among other, add some natural isolation for business-logic layer and cover it with safety net of unit tests.
However, it's not all unicorns and rainbows and unit-test may cost, and sometimes they cost a lot. Good unit tests are isolated (i.e. deal with small chunks of code). This means that you have to add layers of abstraction in order to put your classes under the test.
Having that said - the value of the unit-tests is proportional to the amount of abstract business-logic you are going to introduce in your project. You may think of it also this way - if it is overkill to add abstract layers to your architecture - don't add unit-tests - they will only make things more complicated (architecture and build wise).
With this approach most of the code you probably write is related to "how to display this and that" or "how to signal server in this and that case". This sort of code is obviously heavily depend on platform and this mean that if you do want to put it under test you'll have to mock lots and lots of Android specific code\behavior.
Now, Android is somewhat specific platform. It was designed to be both performance optimized and allow developers to start and produce apps quickly. Often this means some amount of "swiss-knife" classes you have use\extend and generally this speeds up writing code, but mocking those classes can become a real hell. Not to mention that you have to have understanding of how platform works under the hood to make those mock useful. In other words overhead from making those test is going to be high.
Another thing that is wrong with testing presentation layers is that they tend to change much more dynamically than business layers. And, of course this mean that you'll have to refactor thee tests which adds even more overhead.
I have to say one thing about various utility/helper classes though. Even if these classes are belong to presentation layer and do depend Android code, but do some rather non-trivial logic and it is easy to mock and write unit tests for them, it might actually be a good idea to do this. However, if you do have lots of such code - this is might be a signal that you haven't designed your architecture/layering well, and need to rethink what you are doing.
Will it be overdesign to add abstract layer that is separated from the platform to your application (seems like in your case it will)? If yes - do not use unit-tests - they will only slow you down. If no - do use them.
Are you going to refactor a lot? If that's large project with lots of code and thus maintenance - you probably will, so invest in layering and unit-tests (but, at a glance, it does not seem that this is your case). If that is not your case - do not bother with unit-tests and go fast.
UTesting in Android generally takes relevance when you are using some layering with a good architecture. Nowadays the most popular is Clean Arch, which is all about maintainability and testability. Every part of the architecture has exactly one purpose. We just need to specify it and check that it actually does its job every time.
Leaving the architecture besides any good modular and decoupled design will contain business logic in functions and classes, and if those follow single responsibility principle (they should), then likely should be tested.
Local tests: Unit tests that run on your local machine only. These tests are compiled to run locally on the Java Virtual Machine (JVM) to minimize execution time. Use this approach to run unit tests that have no dependencies on the Android framework or have dependencies that can be filled by using mock objects.
Instrumented tests: Unit tests that run on an Android device or emulator. These tests have access to instrumentation information, such as the Context for the app under test. Use this approach to run unit tests that have Android dependencies which cannot be easily filled by using mock objects.
Robo test is a testing tool that is integrated with Firebase Test Lab.Robo test analyzes the structure of your app's user interface (UI) and thenexplores it methodically, automatically simulating user activities. Robo testalways simulates the same user activities in the same order when you use it totest an app on a specific device configuration with the same settings. Thisrepeatable testing approach lets you use Robo test to validate bug fixes andtest for regressions.
Robo test captures log files, saves a series of annotated screenshots, andthen creates a video from those screenshots to show you the simulated useroperations that it performed. These logs, screenshots, and videos can helpyou determine the root cause of app crashes. These Robo test features can alsohelp you find issues with your app's UI.
Test Lab also uses the stats to create a visual representation of the Robotest in the form of a crawl graph. The graph has screens as its nodes andactions as edges. By following the edges between screens, you can get an idea ofhow Robo test traversed your app throughout the crawl.
Depending on the complexity of your app's UI, Robo test mighttake five minutes or more to complete a thorough set of UI interactions. Werecommend setting the test timeout to at least 120 seconds (2 minutes) for mostapps, and 300 seconds (5 minutes) for moderately complex apps. The default valuefor timeout is 300 seconds (5 minutes) for tests run from Android Studio andthe Firebase console, and 900 seconds (15 minutes) for tests run from thegcloud command line.
If your app takes a long time to start, Robo test can throw an error, and won't beable to crawl your app. This only happens in cases of extremely long start-uptime, and can only be resolved by revising your app to make it start faster.
Sometimes you need more control over your tests. For example, you might want totest a common user journey or provide specific UI input like a username andpassword. Robo scripts can help. To learn more about Robo scripts, see Run aRobo scriptand Robo scripts referenceguide.
Robo tests use the Android API to perform actions on Android UI widgetsdirectly. That helps the tests explore your UI automatically, but also meansthat they need to be able to extract an Android UI hierarchy for a screen inorder to run tests on it.
If a screen in your app doesn't use Android UI widgets, Robo tests fall back onMonkey Actions to test that screen. Unlike the more methodicalRobo test actions, Monkey Actions simply simulate tap events on semi-randomlocations on a device's screen.
You can use Robo test in the Google Play Console when you upload andpublish your app's APK file using either the alpha or beta channel. Robo testruns on a set of popular physical devices from different geographic locations,providing test coverage across various form factors and hardware configurations.To learn more, seeUse pre-launch reports to identify issues.
Robo test supports test account sign-in, and also allows you to enter predefinedtext into fields in your app. For custom sign-in and other predefined textinput, Robo test can enter text intoEditText fields in your app. For each string, you need to identify the EditText fieldusing an Android resource name. To learn more, seeAccessing Resources.
Robo test searches for EditText fields with an Android resource name thatmatches a supplied regular expression. If Robo can't find a matching field,it doesn't input your text, but otherwise continues its crawl as usual.
If Robo test can't find an activity matching your deep link, Test Labignores the link. Deep link issues are usually the result of a discrepancybetween the provided deep link and its definition in your app. Check boththe provided URL and your app for typos or other inconsistencies.
Test Lab supports apps that use theApp Licensingservice offered by Google Play. To successfully check licensing when testingyour app with Test Lab, you must publish your app to the production channelin the Play store. To test your app in the alpha or beta channel usingTest Lab, remove the licensing check before uploading your app toTest Lab.
f448fe82f3