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)
Related
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.
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.
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.
I have my unit/Robolectic tests located in
/app/src/test/java
This is made to distinguish android instrumentation tests located in /app/src/androidTest/java
How can I only run these unit tests which don't need whole project to be built (which is time consuming) from command line?
Is there any gradlew/java command?
I want to obtain the same result as if running from Android Studio junit tests from specific dir.
Sure. I assume you don't have any flavour:
./gradlew testDebug -Dtest.single=<your test class>
I am creating a unit testing project for my application. It was working fine before. but I had updated the ADT plugin and android SDK. after that I could launch this project but cannot separately run the test cases. It will execute first test case and then stop. Before I could manually execute the second testcase. But now when I tried to do that I got error "Test launch failed due to internal error: Running tests on UI thread".please help me to solve this...
note:using robotium 3.2.1
Are you running the indidual method from a test from the Eclipse Junit window? Try running the test method from project explorer. Right click and run from the Project Explorer, not the JUnit window.
RightHandedMonkey's work-around works for me.
It also looks like this is a known issue and will be fixed in ADT 21 (see: http://code.google.com/p/android/issues/detail?id=34170)
There's also a changelist there to pull the fix if you are building the ADT from source.