Automate Android Espresso test cases using Jenkins - android

I've been trying to automate android espresso test cases using Jenkins pipeline on mac mini, we have pipeline up and running for Android build and sonar test cases are not included. I have installed SDK created AVD and Emulators as well but unfortunately I'm not able to make it run the test cases.
(environment variables JDK, Android SDK, Gradle, Git in Jenkins config is all setup correctly)
Is there any blog/Article that can help me to setup the pipeline cause I'm running out of options, I googled but no luck, found some articles but those were outdated.
Please suggest if you have any ideas or if you have worked/working on same scenario..!!

Related

Build problems: Faulty Smali code on one machine/account working APK on another

I have two user accounts on Ubuntu 22.04, Android Studio (and all build tools installed on both. For my main account everything works, on the other, the Android app builds fine but behaves differently. This wrong behavior only occurs when building the app on my main account, but not when someone else builds it or the CI runner creates an APK.
It does not matter whether I build it from the command line or from within Android Studio.
I am desperately looking for an explanation or even for ways to debug this. Isn't there some command that prints all environment variables, all paths to all tools, configs, etc… involved in the build process to give me some clue as to what is going on?
This issue only affects building Android apps. Building other JVM-based software (Spring, even mixed Kotlin+Java sources, traditional JEE services) works perfectly fine.
I copied the project folder to other machines, set up a VM, and freshly checked everything out from git and the same reproducible behaviour occurs: Building on my main machine results in a runnable Android app, which exhibits bugs that do not exist in the source code or in the libraries used, building it anywhere else results in an app, which behaves as it should. We even verified that building the app on my main account produces different smali code compared to any other build setups.
I tried manually installing the Android SDK, tried managing it from within Android Studio installed from the JetBrains, flathub, snap store… no dice.
How to debug this?

How to configure travis yml for running webdriverio tests on osx with android emulator?

I have few automation tests using webdriverio which I want to execute on osx using travis ci.
Need some help or examples on travis ci + android sdk + android emulator + nodejs (webdriverio)
Please let me know anyone is having an example .yml file for such tests.
My confusion is which should be the language android or node_js?
How to launch the android emulator ? Is it possible to get existing android avds to just start instead of creating new ones as they take too much time?
This is my current travis yml.

Travis CI still failing with Espresso test - Android

I've got my travis CI set up with espresso instrumental testing for my android library but some test fail on Travis CI while on my local machine (emulator and physical device) everything is okay and all test are passed..
I don't understand why on the server side someone fail, while on the local machine in my ide, with the same script command everything is okay.
Can someone help me out?
Thanks
Instrumented UI tests using Espresso Testing Framework depend on the emulator that you created.
We normally use Android Studio locally, and a different one in CI build servers.
The chosen server is not the reason of the failure, probably the screen size of the emulator.

Porting JUnit tests to Android Testing Framework

I'm planning to port my JUnit tests to Android Testing framework.
Some of the tests only involve the JVM but not the Android system, is it still necessary to port them? Android is using Dalvik and will replace it with ART(Android Runtime) in Lollipop, both of which are different from the JVM (Please correct if I'm wrong.). In this sense, it seems necessary to port all the JUnit tests to the Android Testing framework.
However, some tutorial argues that
"If possible, you should prefer to run your unit tests directly on the
JVM as the test execution is much faster compared to the time required
to deploy and run the test on an Android device."
http://www.vogella.com/tutorials/AndroidTesting/article.html#androidtesting
I'm not an expert on JVM, Dalvik nor ART. Can someone clarify this issue? Is it necessary to port the tests that only involve JVM to Android Testing Framework?
Thanks!
This depends on what you would like to test and the environment in which you run your tests in.
In theory, pure non-Android-specific Java code (aka. POJOs) you write will work on whatever virtual machine you run it on--JVM, Dalvik, or ART.
If you agree with that theory, then if you are already running your tests on a JVM, there is no need to run it on Dalvik or ART, especially if you consider the speed at which JVM will execute the tests. (Running it on Dalvik involves building the apk, and installing it, and running an adb shell command which can take some time...)
Of course, if you feel that the behavior of your Java code may change depending on the runtime, then you should probably port those tests over to your Android tests.
Recently, I checked out Android Testing Support provided in Android SDK.
As far as I know, you can write Unit Tests, which can be executed directly on JVM in your computer or CI Server (e.g. Jenkins) without Android device or emulator. The only requirement is the fact that these tests and code, which is tested have to be written in pure Java without any dependencies to Android SDK and Android Context. These tests have to be located at src/test/java directory. You can switch test artifact in Build Variants in Android Studio to "Unit Tests" and run your tests with IDE. you can also run them via Gradle wrapper with the command: ./gradlew test
If your tests or code, which is going to be tested depend on Android SDK and Android Context, you should use Android Instrumentation tests, which have to be located in src/androidTest/java directory. These tests have to be executed on Android device or emulator. You can switch test artifact in Android Studio to "Android Instrumentation Tests" and run your tests with IDE or use Gradle wrapper command ./gradlew connectedCheck
You can check official article about Unit Testing at: http://tools.android.com/tech-docs/unit-testing-support . It's worth reading. It's a bit outdated, because now you can use build tools: 1.1.0 instead of 1.1.0-rc1, but rest of the information is up to date. After reading this article, you should understand this topic better.

What tools use and how do continuous integration and test in Android with eclipse?

I have some experience in Android, and I have been working always with Eclipse. Now I want to start to develop doing test and continuous integration, so I have been researching in Google, but I have found so much different information, and I'm a little confused.
I have seen Jenkins as a good option for CI server, Robolectric for tests, and I have read about ant, maven and gradle, but, are this the best options? How I configure this tools to work together in Eclipse? Do you recommend me something better to start?
Thank you
For my part, I use Android Studio, and gradle. I use TeamCity as the continuous integration server, which supports Gradle.
I have my unit tests launched automatically by TeamCity, using Gradle, on a desktop Android device (kind of mini-computer), it's pretty usefull.
I've started tests with a phone plugged in USB on a TeamCity agent, that works very well too.

Categories

Resources