Gradle + Robotium + Jenkins - android

I am trying to set up a CI environment with Jenkins and Robotium. I want to use the same project for both built and test, but seems so tricky to get all working. I was wondering if someone had something like that working and if it can publish at least build.gradle and the project structure. Thanks.

Have been running in production for a few months now. See this question for a sample project and video of how to use robotium with gradle.
https://stackoverflow.com/a/23295849/1965124
As for the jenkins side of things:
Install the android sdk on the machine that will be running jenkins
set up android home variable
install the android plugin
run the following tasks from inside a jenkins job: clean connectedAndroidTest
after running 1 build (it will fail the first time), change the local.properties file to point to the local installation of the android sdk.
Let me know if you need any more pointers, its not as hard as I initially thought it would be.

I configured TeamCity as CI server. Also, project builds by Gradle.
The main idea is to execute gradle connectedInstrumentTest, that task will execute all project's tests on all connected devices, then it will put the test results in standard ant-junit format, so then you can set Jenkins to parse app-folder/build/instrumentTest-results/connected/*.xml test results.
If you got more questions, you can post them to the comments.

Related

Android Studio 3.2 empty test suite

I have created a new project in Android Studio 3.2. Without making any changes I am not able to run all the unit tests in the group. I receive and error saying No tests were found
I am attempting to run the tests by right clicking on the group and clicking Run Tests.
I can run the unit tests if I open up the file and click on the run button next to the class declaration. I can also run the unit tests if I open the project in Android Studio 3.1.4. I can right click on the group and run all the unit tests with no error.
Looking at this bug report, I think it should be fixed in 3.2.1: https://issuetracker.google.com/issues/115708445#comment12
After spending an entire day trying resolve this while writing some unit tests I found one workaround that works for my project.
Basically what my workaround is to add Build to the Before launch options.
After adding this option I'll occasionally get the No tests found error message but simply rerunning the test worked every time after adding that setting.
I'm not sure if it will help with everyone's problem but it seems to have mitigated the issue with my project. Hopefully this works for someone else as well.
The workaround until the bug is fixed is running tests in terminal, just type:
./gradlew test
or
./gradlew testDebugUnitTest. If you are using Windows replace ./gradlew with gradlew.bat. You can also download Android Studio 3.3 Canary from here https://developer.android.com/studio/preview/ – there aren't problems with running tests via this version.

Automating gradle to build the application package(.apk) from the code

Recently, I was working on a project in which we have a code-base and we make some changes in the application and make the application available for testing to the tester.
The changes are variables changes such as our test site name, icon and splash screen.
What we are trying to achieve is that without opening Android Studio, we can make the application package(.apk) for the code base that we have. It will save a lot of time for us
We have searched for several options which are Jenkins CI etc, but have not been able to do so.
Any sort of help regarding this topic will be appreciated.
You can run a gradle task from the console / terminal.
Go to the project root folder and run gradle + command, generally the command is gradle assembleDebug or gradle assembleRelease depending on the build type you are aiming for.
You can check the existing gradle tasks on Android Studio

Unable to run Amazon Device Farm build in Jenkins using JenkinsCI Plugin

I have successfully automated my test in ADF using Appium TestNG framework. I was trying to run the same build in Jenkins for continuous integration.
I have taken freestyle project in Jenkins.I am getting error. It is unable to find the pattern of .apk file. I am giving Application name the just apk file name e.g. android-debug.apk and in the test giving the" target/zip-with-dependencies.zip.But I am getting following error:enter image description here
Below is the picture of my configuration settings:enter image description here
Please provide my solution of this issue.
I work for the AWS Device farm team.
Good to hear that you are using the Jenkins plugin.
The plugin configuration takes your application and tests files assuming it is a part of your workspace.
Way to approach this :
Trigger a run without any tests or apps. This will create the workspace folder for a project if it is the first run.
Thereafter your tests and app go under the workspace which you can upload through the UI or place in the workspace folder on your Jenkins project.
The path in this case becomes **/yourapk.apk for your application and **/tests.zip for your tests.
Hope that unblocks you. If not let me know and I can help you further.

Android Local Unit test with coverage report from command line

I am working on a new project for Android. Currently, I am using Android studio as IDE. I need to run Unit test and System (CI) test flows which can be run on both Local machine (JVM) and Emulator/Real Device for instrumentation.
Note that I am running all unit tests via command line.
For get the code coverage of the Emulator/Real Device I am using Jacoco.
and running the following command: gradlew createDebugCoverageReport
However, I can't find any way to run the Local machine unit test with coverage report from command line.
The only way is to run it from the android studio by selecting "Run XXX with Code Coverage":
Can you please advise if it is possible to run local unit test from command line with coverage. And get the report as an html file?
Thanks,
Zachi
If I understood correctly, you are trying to run the tests with coverage ability of the IntelliJ-based Android studio.
It basicly can be done using a Command Line Tool of the IntelliJ.
You can read more about it here, but it generally allows you to accomplish everything that can be done from GUI via the command line:
IntelliJ creating command line tools
For more general info regarding the coverage of the IntelliJ tools you can read here:
IntelliJ Code coverage
Hope it helps, good luck.
At this moment there is no default task to create reporting for Junit (local) tests in the gradle Android tools.
However, it's easy to create those.
Just follow the instructions to integrate the custom jacoco.gradle file here:
https://gist.github.com/mrsasha/384a19f97cdeba5b5c2ea55f930fccd4
You will then have tasks like these: test[Flavor]UnitTestCoverage
So to generate the reports, you just have to:
$ ./gradlew test[Flavor]UnitTestCoverage
The report can be generated using the android studio, after you run the test with coverage the results window appears, click the button bordered with red
Check this image:
By running ./gradlew tasks in the terminal if you are using the gradle wrapper or gradle tasks you will have a list of the available verification tasks (see the screenshot below):
You can refer to this link for more thorough test command lines.
You can use testDebugUnitTest, run it as ./gradlew <your_module_name>:testDebugUnitTest and it will run tests related to this particular module + it will generate an html report under your_module/build/reports/tests/testDebugUnitTest folder, with the coverage.

Tests run via maven, and adb, but not IntelliJ - why?

I'm working on a project defined with maven, and I can successfully run the maven script to build the app, and run automated (junit 3.8.2) tests on the device with instrumentation.
Likewise I can use adb to run the instrumentation tests successfully.
However running the instrumentation tests from IntelliJ is failing with this:
Running tests
Test running startedTest running failed: Instrumentation run failed due to 'java.lang.ClassNotFoundException'
Empty test suite.
Logcat shows the not found class as org.junit.Test. The IntelliJ project was created by importing the root pom, and otherwise works fine. I just had to create a Run Configuration for the tests, specifying the instrumentation runner.
I've tried on several devices and they all provide the same result.
I would expect the junit Test class to be in the OS framework on the device, so I'm confused as to why it's not being found. I've tried setting the junit dependency in IntelliJ from Provided to Compile, but that makes no difference.
What have I missed?
Okay this is an old question, however, most likely you'll have different classpath in maven as compared to intelliJ. You can solve this pretty easily by going to the intelliJ project Structure ( File --> Project Structure or Ctrl + Alt + Shift + S).
Under Project Settings, click Libraries and manually add the library that is missing.
I do find it strange though that IntelliJ is not picking up maven dependencies. After all, if maven runs it, so should intelliJ - it has the best maven integration available in an IDE and VERY VERY much better than that of eclipse. So your issue does make me feel something else is the root cause...
Perhaps you can ask the IntelliJ people?
More info on your part could allow us to give better feedback...

Categories

Resources