dimanche 27 mars 2016

android - gradle task called mockableAndroidJar how to actually use it in unitTests

When i ran ./gradlew tasks i notice a build task called mockableAndroidJar. The description says the following :

Creates a version of android.jar that's suitable for unit tests.

Can someone give me an example how i can use this jar mock in code ?

From the android tools page i saw the following:

Unit tests run on a local JVM on your development machine. Our gradle plugin will compile source code found in src/test/java and execute it using the usual Gradle testing mechanisms. At runtime, tests will be executed against a modified version of android.jar where all final modifiers have been stripped off. This lets you use popular mocking libraries, like Mockito.

But my question is can someone show me how i can make my test use this new android.jar file instead of the current one that has finals on the classes ? How to point tests to use this jar instead ? I saw this question but its not showing me how to use this in tests, only gives theory. I actually ran the following command from shell:

./gradlew mockableAndroidJar

and the output was the following:

    $./gradlew mockableAndroidJar
Picked up JAVA_TOOL_OPTIONS: -Xmx512m -Xms64m
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=768m; support was removed in 8.0
Incremental java compilation is an incubating feature.
:app:mockableAndroidJar UP-TO-DATE

BUILD SUCCESSFUL

Total time: 1.226 secs

So i thought there would be some change in my directory structure but i dont see any. Is the jar file automatically swapped for me ?

Aucun commentaire:

Enregistrer un commentaire