Android - what is gradle task connectedCheck used for - android

When I run the following command I get a description of connectedCheck but I'm still not sure what it's used for. Could anyone give me a real world example?
./gradlew tasks prints
...
Verification tasks
------------------
check - Runs all checks.
connectedCheck - Runs all device checks on currently connected devices.
connectedInstrumentTest - Installs and runs the tests for Build 'Debug' on connected devices.
deviceCheck - Runs all device checks using Device Providers and Test Servers.
...

Command ./gradlew connectedCheck executes instrumentation tests located in src/androidTests/ directory on connected Android device or emulator. Such tests can have dependencies to Android API. These tests can be simple assertions or UI tests with Espresso framework or something similar. Yesterday I wrote post about Android automated tests including more detailed description of them. You can check it out here.

Related

Show android emulators when running tests via gradle managed devices

When running android espresso tests via gradle managed devices, i.e. by running:
./gradlew pixel4api30DebugAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.aaa.bbb.ccc.Suites.TestSuite -Pandroid.experimental.androidTest.numManagedDeviceShards=3
Is it possible to have it display the emulators while running the tests so that you are able to see what is happening?
You can use the --enable-display switch:
./gradlew pixel4api30DebugAndroidTest --enable-display
But keep in mind that this will not work with ATD images.

How to exlude tests when generating coverage reports using Jacoco on Android with gradle

I want to run a single Gradle command which generates a coverage report as well as runs a specific set of tests, not every test in the package. In this instance, I want to generate the report on my instrumentation tests and not on my UI tests.
I have set up Jacoco so that I can run the Gradle command
./gradlew create<package-name>DebugAndroidTestCoverageReport to run all of my tests in the androidTest folder.
I've tried ./gradlew create<package-name>DebugAndroidTestCoverageReport --tests "com.myproject.test.*" to only run the tests located in the test package but this returns the error Unknown command-line option '--tests'.
Using the Gradle command test --tests "com.myproject.test.*" Works fine and runs the specified tests, but does not generate the coverage report.
Is there a way that I can have test filtering while still generating the coverage report?
After some searching I stumbled upon this question Android, Gradle. How start specific instrumented test method? which gave me the answer.
In order to filter out test cases by package you can use
./gradlew create<package-name>DebugAndroidTestCoverageReport -Pandroid.testInstrumentationRunnerArguments.package=com.example.test
This command will generate the coverage report only on the specified tests.

connectedAndroidTest task runs all test even when class is specified

I m trying to run instrumented unit tests using connectedAndroidTest. At first I jus wanted run to particular class using cAT. So I tried below command
./gradlew app:connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.company.test.data.model.TestClassName
but it runs all the tests including the robotium and espresso tests which were written. I gone through lots of StackOverFlow posts, in all posts the answer is the above specified command.
when I tried
adb shell am instrument -e class com.company.test.data.model.TestClassName com.company.test/android.support.test.runner.AndroidJUnitRunner
It ran the tests as expected. The problem is I wont get jUnit Reports by the adb command but cAT will provide me test reports, code coverage reports as required.
Does anyone have solution for this issue to run specific tests?
It was actually the problem with gradle version. The developers had set the gradle version to 2.3 in which I was facing the issue. Then I have updated the gradle version to 2.10 and the issue is fixed.

How to use the deviceCheck task to run tests on remote devices

On http://tools.android.com/tech-docs/new-build-system/user-guide, the following tasks are defined:
assemble The task to assemble the output(s) of the project
check The
task to run all the checks.
connectedCheck Runs checks that requires a
connected device or emulator. they will run on all connected devices
in parallel.
deviceCheck Runs checks using APIs to connect to remote
devices. This is used on CI servers.
build This task does both
assemble and check
clean This task cleans the output of the project
I am now setting up a Jenkins CI to run my (Espresso) tests and the deviceCheck task description seems related to that. But I couldn't find any further documentation or examples on how to use this task on CI server to execute the tests on a remote device. Does anyone know how to use it?
I would recommend running the tests with: Spoon. It's easy to setup, has lots of nice out of the box features. e.g. good test reports, screenshots ++.
I am using it on my Jenkins CI, and it works really well! I have connected multiple devices to the CI-server, and the tests runs on all of them.

Instrumentation error running RoboElectric 2 tests in IntelliJ

I have a simple Android project that makes use of RoboElectric 2 and Maven.
I am able to run my tests fine using:
mvn clean test
but the tests fail to run inside IntelliJ IDEA . I get this strange error when attempting to run the tests from IntelliJ IDEA
Running tests
Test running startedTest running failed: Unable to find instrumentation info for: ComponentInfo{com.example/android.test.InstrumentationTestRunner}
Empty test suite.
I get no other errors in the IDE and everything compiles and deploys to device correctly from within IntelliJ.
"Unable to find instrumentation" suggests you try to run this as Android test - is it the case? It should be run as JUnit test (usage of RoboElectric suggests you've written standard unit tests)

Categories

Resources