Running multiple test with connectedCheck using Espresso - android

I am using Espresso. I have multiple tests written, all in different classes but the same project. When I run I remove all but one class and try running, it runs fine. However, when I have them all in my project and try running the second one always fails.
All of my test are pretty basic right now. They just have setUp() and one testMethod().
Can someone tell me what I am doing wrong?
NOTE: I run via terminal with command gradle appName:cC

I found my answer. I need to add the Spoon Gradle Plugin

That's one option, but you don't have to, you can still use gradle command connectedCheck
Find out how to run the tests (including running tests for a specific module and on multiple devices) here at this Google example:
https://github.com/googlesamples/android-testing-templates/tree/master/AndroidTestingBlueprint

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.

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.

Execution of spoon task along with running instrumentation test

I have been working on functional testing in Android using Espresso. After adding it successfully I thought of creating reports for the test I added.
For reports I used spoon. Set it up correctly and ran it using the script containing the following command given here
http://square.github.io/spoon/
Query :
But my query was that is there any possibility by which we can run this spoon task run through AndroidStudio menu option that runs functional tests.
Please let me know :
If it is possible at all or not ?
When possible, what to do for the configurations ?
Note : from command line gradle spoon task is working fine and creating reports
Thanks

Robotium (and Robotium Recorder) checking default application and location of test results

I am doing a simple series of tests with Robotium Recorder on Android Studio. I have created my test cases and had a few questions:
One of my tests is to click a URL link and to make sure that the default application dialogue/internet browser is displayed. I don't see an option to do this from the recorder (I wouldn't expect it). I have been looking through the documentation for the solo object and do not see anything that would help me out. There has to be a way to check this.
Once a test is ran from Android Studio, where would the file containing the test results reside?
According to second question: I'm not sure that Robotium already creates any tests reports. You may use for it additional addons like Spoon or Emma.
Read: Creating Test Reports for Android with Spoon and Emma
I know also that Robotium can do a screenshots during the run of tests, but already I don't use this framework so please find on your own how to do it and where screenshots are placec if you feel a bit interesting.
Already, for creating instrumentation tests report I use Gradle. It generates quite good HTML reports. There are at least two ways to make it
in Android Studio, on the left panel, choose Gradle then app, verification, finally connectedAndroidTest
if you're familiar with Unix console go to your project location and just run the command:
./gradlew connectedAndroidTest
NOTE: On the first time it might be needed to run before chmod u+x gradlew, if console would say that you don't have enough permissions to do it.
SUGGESTION: if you make one of your test failed, in generated by Gradle test report you would find a location of HTML generated tests report.
Gradle test report would look like this if all would run successful or this, if at least one would fail.

Gradle + Robotium + Jenkins

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.

Categories

Resources