How to run Eclemma code coverage tool for android Junit test, not for Junit test? Can any one please help.
The easiest way would be to add ant build files to both projects (main and test) and then use the specific ant targets to generate the coverage report.
Then you can import the coverage report to EclEmma.
To add the ant build you first need to disable Project -> Build Automatically in Eclipse to avoid conflicts.
These steps are described in http://dtmilano.blogspot.ca/2011/07/eclipse-android-and-emma-code-coverage.html.
Related
gradle-ndk-gtest-sample
Android NDK with
README.NDK
I have been trying to configure my Android NDK project for use with Google Test. I started with native-activity sample as the base project and began following the guides above. I inserted the code from the first link into my root build.gradle. I am really not having any success. It looks like i was able to generate the test library:
./libs/googleTest/1.7.0/lib/osx/libgtest.a
./libs/googleTest/1.7.0/lib/linux/libgtest.a
./app/.externalNativeBuild/cmake/debug/x86_64/libnative_app_glue.a
./app/.externalNativeBuild/cmake/debug/x86_64/libFOO.a
./app/.externalNativeBuild/cmake/debug/x86_64/libgtest.a
./app/.externalNativeBuild/cmake/debug/arm64-v8a/libnative_app_glue.a
./app/.externalNativeBuild/cmake/debug/arm64-v8a/libFOO.a
./app/.externalNativeBuild/cmake/debug/arm64-v8a/libgtest.a
But I don't know where to go from here. How do I actually run the tests and see if they passed?
Try something like https://github.com/DanAlbert/GTestJNI. It's an alternative test runner for JUnit and GTest that exposes GTests as if they were JUnit, so you can just run your normal androidTests and they'll run your GTests for you.
Some day I want to get this either added to the NDK or at least made trivial to add to a project as a git submodule or something, but for now you can merge the pieces of that into your project.
I am building an Android Studio/Gradle project on TeamCity server. I am somewhat new to TeamCity. Currently, the unit tests auto-generated by Android Studio are run automatically when the project is built on TeamCity and are displayed under "Tests" . I also have an instrumented test (a test which runs on the connected android device), but it does not get run automatically like the unit tests do.
My solution was to add a Gradle build step in TeamCity to run the instrumented test. So far, I've had little success. I used the gradle tasks uninstallAll connectedAndroidTest, which runs the instrumented test, but the test result does not show up under "Tests" along with the unit tests. If the instrumented test fails, the build fails, but the failed test still does not show up under "Tests".
What am I doing wrong? Is there a correct way to run instrumented tests on TeamCity?
The connectedAndroidTest will output files specifying test results according to this pattern:
HTML test result files:
path_to_your_project/module_name/build/outputs/reports/androidTests/connected/
directory.
XML test result files:
path_to_your_project/module_name/build/outputs/androidTest-results/connected/ directory.
(from here)
Using that output file you can use the XML Report Processing feature of TeamCity. In your Build Configuration just go to the Build Features tab and add the XML Report Processing feature. Use the Google Test option and point it to the report output directory like so:
After that you should see your instrumented test results show up in your builds just like regular JUnit tests:
You can tweak test task:
test.dependsOn uninstallAll, connectedAndroidTest
Another way would be to include your test (though not sure if this will work as I am not sure what uninstallAll and connectedAndroidTest tasks are doing):
test {include 'org/foo/**'}
I have been working on a module, whenever it is build using "gradlew assemble"it will generate an aar file in build/output folder. I have created few tests extending the InstrumentationTestCase in android app module, I want to run those tests whenever I build the library using gradle command.If compilation of tests "pass" the build(aar) should happen else it should fail. Could any one please help me on this?
Running gradlew clean connectedCheck should run through all of your tests on all connected devices and will also build out your aar file. That's the easiest way.
I am using make for building and Robolectric as a framework for running Android tests. I would like to calculate coverage of my app. For instrumentation tests I used to use emmalib. What is the best way for me to set up coverage calculation in this case? I can't migrate to gradle or maven.
Are you bound to Emma? How about using RoboElectric + Cobertura code coverage? (I think you could just use a CLI for the above combination)
So options
1.) RoboElectric + Cobertura - CLI alone probably for someone not on ANT
2.) JaCoCo might have some useful options
3.) Pure Android Testing + Emma/EclEmma
Useful Link trails to follow
Generating android code coverage though changes in build.xml and ant.properties
Android Gradle Code Coverage
https://intellectualcramps.wordpress.com/2013/08/18/code-coverage-of-robolectric-tests-using-jacoco/
https://bitbucket.org/ravidsrk/androidstarter
EDIT:
Well most of the tutorials I have come across use ant unfortunately, and I don't think it would be a bad idea for you to move to a recommended build system like Gradle so it opens up a lot options. But for JaCoCo you could take a look at here: https://intellectualcramps.wordpress.com/2013/08/18/code-coverage-of-robolectric-tests-using-jacoco/
UPDATE:
Moved this from comments to the answer section for information to anyone wanting to see this and because this is a bounty question
One solution would be to use Cobertura to generate code coverage, which can be integrated in eclipse and also run by an ant build script.
A template project of such an integration can be found here: https://github.com/adgllorente/android-cobertura-boilerplate
Note that all of the magic happens in the build.xml of the Test project. Theses tasks should probably be generalised to a custom_rules.xml file so you can still use android to update your projects.
Finally, for Gradle you have many different options:
http://raptordigital.blogspot.nl/2014/08/code-coverage-reports-using-robolectric.html
http://chrisjenx.com/gradle-robolectric-jacoco-dagger/
https://stackoverflow.com/a/25037742/2771851
Note that you can always use Gradle as a secondary build system just to generate the coverage reports. (but a second build system will introduce a lot of overhead)
jacoco sometimes does not work with Robelectric and powermock runner you can use clover an atlassian tools it is now open source tool.
I have an Android project and JUnit tests in my code.
I wanted to know if there is an ant task to run some tests.
In fact, I have several classic tests which are run using JUnit to test several methods, and some tests that need an android emulator or at least need to be run on an android device.
As I didn't find any documentation, I wanted to know if it's possible to do that kind of thing.
Like
junit-android dir="."...
Thanks a lot for your help and time.
Just to be clear because I've search on the web and didn't find many things, so hope you can help.
I have an Android project that contains NO activities.
Actual build.xml file:
I compile java source code
It generates me a .jar file.
I need to run some tests defined in my project/tests/ folder, using
the previous generated library. Thoses tests need to be runned on an
emulator device using ANT build file, whithout being dependent of
Eclipse.
Project:
src (java source code)
gen
bin
res
tests (Android test project)
AndroidManifest.xml
build.xml
...
The test project generated is containing a build.xml that has been automatically generated using android update command. Sadly, there is no task "run-tests". And how do I specify that I would like to use my library for those tests?
Everything you need to create and run android test projects from the command line, provided by Google itself ;-)
http://developer.android.com/tools/testing/testing_otheride.html
The command line you need is something like:
adb shell am instrument -w <test_package_name>/<runner_class>
To call that from Ant, use the <run-tests/> task, described here.
Create a target in your build.xml like this
<target name="run-tests">
<test-junit includedTests="pathToPackageContainingTests}/*.class" />
</target>
Then you can simply do this
ant clean release run-tests