Android-maven-plugin, instrumentation and testSize

I use maven to create, run and test tools for Android applications. The Android testing system has three different test areas @SmallTest , @MediumTest and @LargeTest , and the Android maven plugin has the ability to select the testing area through testTestSize or test / testSize . This parameter can be one of small|medium|large and can run your tests from the corresponding area.

But what can I do if I want to run small and medium tests at the same time, and not just small or not just medium ones? Is there any solution to this problem?

+4
source share
2 answers

Here's how the Android SDK is designed and should work at the moment, according to the InstrumentationTestRunner API doc :

Performing all the small tests: adb shell am instrument -w -e size small com.android.foo/android.test.InstrumentationTestRunner

Running all average tests: adb shell am instrument -w -e environment size com.android.foo/android.test.InstrumentationTestRunner

Running all the big tests: adb shell am instrument -w -e size large com.android.foo/android.test.InstrumentationTestRunner

Even if you use the regular adb command to run the test, you need to use two processes to run the small and medium level test separately, one after the other. Android Maven Plugin is another shell of the adb command, so there is no way to change the default behavior using the AFAIK configuration in the Android Maven plugin.


If you read the InstrumentationTestRunner API doc more carefully, you will notice that there is an interesting use of commands:

Filter a test run for tests with a given annotation: adb shell am instrument -w -e annotation com.android.foo.MyAnnotation com.android.foo/android.test.InstrumentationTestRunner

If used with other parameters, the final test run will contain the union of the two parameters. for example, "-e size large -e annotation com.android.foo.MyAnnotation" will only run tests with the LargeTest and "com.android.foo.MyAnnotation" annotations.

An annotation configuration has been added as an experimental API (marked as @hide, see this version history for more details) and has not been registered in the tool options list am . Theoretically, you could create your own annotation class (see SmallTest.java for an example), check all @MediumTest with your @CustomizedTest, and use both the -e size and -e annotations to achieve what you want: run union tests from two annotations at the same time, all in one team.

Unfortunately, android-maven-plugin does not support annotation configuration, see plugin documentation and latest source code . A possible workaround is to use exec-maven-plugin to run a simple adb shell am instrument command.

Hope this makes sense.

+3
source

To use the test size from maven-android, I created a variable in pom.xml:

 ... <properties> <config.build.testSize>medium</config.build.testSize> </properties> ... 

and in the assembly:

 <build> <pluginManagement> <plugins> <plugin> <groupId>com.jayway.maven.plugins.android.generation2</groupId> <artifactId>android-maven-plugin</artifactId> ... <configuration> <test> <testSize>${config.build.testSize}</testSize> </test> </configuration> ... </plugin> </plugins> </pluginManagement> </build> 

I assume that you can also achieve this by providing the android.test.testSize parameter for maven (e.g. mvn install -Dandroid.test.testSize = medium)

Please correct this maven variable if I am mistaken until I find it in the document. BR, M.

0
source

All Articles