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.
Related
I have a project with a single module app and then lots of other modules like search and detail. app has MainActivity and almost nothing else. The other modules have lots of #Composable functions that make up the actual completed application. The individual modules also have tests in androidTest for automated testing.
How can I run the tests declared in each submodule but against the app build apk?
Directory structures may make this clearer:
/project/app/src/main/.../MainActivity.kt
/project/search/src/main/.../SearchComposable.kt
/project/search/src/androidTest/.../SearchTests.kt
/project/detail/src/main/.../DetailComposable.kt
/project/detail/src/androidTest/.../DetailTests.kt
If I run
./gradlew :search:connectedDebugAndroidTest
it will try to run those tests but they don't have an Activity, they only really run from app. Unit tests of course work fine, but automated tests do not.
If I run
./gradlew :app:connectedDebugAndroidTest
Then it will only run those declared within app. I haven't figured out a way to add a dependency from app's androidTest configuration to search/detail's androidTest output (lots of searching, nothing promising yet).
If I run
./gradlew connectedDebugAndroidTest
It will try to run all and fail to run search and detail since they don't have an activity.
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'm trying to fire off various android based gradle tasks e.g. assemble, after 'gradle clean test' is run.
Some background...
My company has jenkins and it is managed by a separate team so I don't have access to configure it myself. On any changes to the remote repo (git) a jenkins job will fire, running gradle clean test and using a build.gradle file that we have inside our repo.
I'm told that this is the only command that the build team will provide and if I want any further actions running, I'll have to configure them inside the build.gradle script.
I am imagining that I can possibly do something like afterTest(:assemble) or maybe addTestListener() but I can't seem to find any examples on google.
Can anyone here help me? Is this even possible or should I ask my build team to allow me to run a diff gradle task depending on what I want?
Configuring CI jobs uniformly is a good idea. However, there is no good way to have additional independent tasks executed when gradle clean test is run. They'd have to at least run gradle clean build so that you can add tasks with build.dependsOn(myTask). (However, keep in mind that build already depends on assemble.) Or they run a custom task such as gradle (clean) ciBuild which by default only depends on test, and to which further task dependencies can be added as necessary.
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
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.