Android Robotium test - NoClassDefFoundError - android

I'm having problems with Robotium being unable to find my app at runtime.
Just to be clear, I've seen a few similar questions on SO however, they seem to revolve around the Robotium Solo class not being found at runtime (or some other 3rd party lib). However, this is slightly different as my Robotium tests can't find the project under test.
The tests are in a separate project which has a dependency on my app project. There are no problems at compile-time but when I try to run the tests I get...
java.lang.RuntimeException: Exception during suite construction
at android.test.suitebuilder.TestSuiteBuilder$FailedToCreateTests
....
Caused by: java.lang.NoClassDefFoundError: com.myapp.mobile.activity.RegisterUserScreen
Where RegisterUserScreen is an activity in my app. This happens on the device and the emulator.
I'm building / running in IntelliJ 12.1.4, against Android 4.1.2 and I see the same result when I attempt to run the test from the command line.
Probably worth pointing out that running adb shell pm list instrumentation from the command line returns the correct instrumentation...
instrumentation:com.myapp.mobile.test.system/android.test.InstrumentationTestRunn
er (target=com.myapp.mobile)
Thanks in advance,
Neil.

In your device go to settings->apps and check whether in installed or running application list name of your testing application name is present. If you find it there then uninstall the testing app as well as your original app (which has to be tested). Many times it happens that either because of different versions/signature mismatch test-application fails to find the target application.

Create your run configuration as an "Android Tests" not as "JUnit"

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.

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.

Writing tests that run on both Android and desktop

Lately I noticed a bug in my Android app which doesn't happen when I run the same code on the desktop (since the app is written on top of libgdx, 99% of the code is the same on desktop and Android.) I decided to explore why by writing some unit tests. However, while the tests run fine on the desktop, I get the "Failed to launch test" error when I try to run the tests on Android:
[2013-03-09 19:06:45 - zzz-test-android] Installing zzz-test-android.apk...
[2013-03-09 19:06:48 - zzz-test-android] Success!
[2013-03-09 19:06:48 - zzz-test-android] Launching instrumentation android.test.InstrumentationTestRunner on 015d15b51d30180b
[2013-03-09 19:06:48 - zzz-test-android] Failed to launch test
The way my project is set up in Eclipse is that I have two projects: A "zzz-test" which contains the test classes and the JUnit3 libs. Then a second "zzz-test-android" project (which was created via "New Android Test Project") which has a dependency on zzz-test.
Any ideas on what I might be doing wrong, or at least a way to get an error message that might be more helpful?
Can it be related with some missing permission in manifest file?

No class def found error for JUnit Test on android

I am having some very bizarre behaviour. I have a large number of test cases for my Android application, and they all work except for one. When I run this one I get a java.lang.NoClassDefFoundError: org.JUnit.test
Yes, I have the JUnit 4 library imported into the project, and my other JUnit tests are running without any problems. What is particularly bizarre is that before I hit this problem I had an error in my code- basically, I tried writing a file to a read only folder. When that occurred, the JUnitTest would execute up to the point where it would hit an IO exception for accessing a part of memory it cannot access. I fix this problem, and suddenly the Android emulator doesn't seem to know what org.JUnit.test is.
I have examined the run configuration for this test class, and it is the same as my others. It is in the same folder as the other tests as well. It also uses the same import statements. Any idea on what is going on?
I am using the Android 10 emulator, and eclipse version 3.7.2.
Edit: To clarify, the error I get appears on Logcat and not in my Eclipse project.

Android: How to Install the Instrumentation APK onto an AVD in a Headless Host

I'm trying to integrate Android JUnit tests with our Bamboo Ant builds. I've already tested the setup locally, and I'm able to run tests.
But when I tried the same setup in our Bamboo server, I get the following error when running the tests:
INSTRUMENTATION_STATUS: id=ActivityManagerService
INSTRUMENTATION_STATUS: Error=Unable to find instrumentation info for: ComponentInfo{com.synapticstuff.guitartabs/pl.polidea.instrumentation.PolideaInstrumentationTestRunner}
INSTRUMENTATION_STATUS_CODE: -1
android.util.AndroidException: INSTRUMENTATION_FAILED: com.synapticstuff.guitartabs/pl.polidea.instrumentation.PolideaInstrumentationTestRunner
Note that I used a custom library for Instrumentation (http://code.google.com/p/the-missing-android-xml-junit-test-runner/), so that I can pull the JUNit xml test results and feed it to Bamboo.
Also, the build agent used in creating the build is an Ubuntu VM, which doesn't have any GUI so I need to do everything via command line. An AVD is already running on that VM.
I did encounter the same problem when I first ran the adb shell am instrument .. <snip> command locally, and I found it weird it worked after running the test from Eclipse.
Looking up the error log, the Android Instrumentation Framework article tells me that
"It's possible that the
instrumentation apk isn't installed on
your device or that the package name
is incorrect in the Manifest file."
so it must be that the instrumentation apk isn't installed.
So, how do I install the instrumentation apk onto the AVD?
Thanks!
There are probably multiple situations that can cause this error, but I got it from not having an instrumented version of the test package installed on the emulator. Documentation is a bit scant, but I don't think there's an "instrumentation APK" that you install onto the emulator (at least I couldn't find such a thing); you build your test application with instrumentation included. Anyway, this is how I run tests from the command line using ant, which now works:
ant instrument install test
and this also works running on Jenkins using the Android emulator plugin (https://wiki.jenkins-ci.org/display/JENKINS/Android+Emulator+Plugin). I found the instrument task in the command line build documentation here: http://developer.android.com/tools/building/building-cmdline.html.
There is another possible reason: the package name is incorrect in the Manifest file.
Check the package name in your unit test project's manifest file first!
I am also one of the few people who downloaded that custom InstrumentationTestRunner (http://code.google.com/p/the-missing-android-xml-junit-test-runner/) and I am currently stuck on this issue! I get the same error message, unfortunately I do not know the answer right now, but will update when I discover something helpful.
In the meantime I looked for other options like this person's Test Runner: http://www.alittlemadness.com/2010/07/14/android-testing-xml-reports-for-continuous-integration/
There is also another discussion related to continuous integration: How to Generate Android Testing Report in HTML Automatically
you can maybe solve this, if you add to your build script:
adb install -r testproject/bin/testproject.apk
checkout first how the apk-file is being named, because i still didn't figure out, how ant is going to do that exactly, but it's being created usually in bin directory.
See also the official android documentation.
I ran into this problem when running my tests against an old Android 1.5 virtual device. After switching to a 2.3.3 virtual device the problem went away. I don't know if the problem is due to the virtual device OS being old or the virtual device being created with old Android SDK tools.
I was running into the exact same problem with running an android build under Bamboo. I found that for some reason the android:targetPackage element in my test project manifest was incorrect. It was set to be the package of my main project, not the test project. For some reason running when running the tests in eclipse eveything worked fine, but it died when I tried to run the ant test at the command line. The instrumentation instrumentation tag read:
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example.blah" />
This was automatically generated by eclipse when I created the project. I changed it to read:
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example.blah.test" />
and suddenly everything ran fine.

Categories

Resources