Junit output using the-missing-android-xml-junit-test-runner - android

I am having trouble setting up http://code.google.com/p/the-missing-android-xml-junit-test-runner/ within Jenkins.
I can get the tests to run and pass in eclipse. When I pull them into jenkins and build via ant I get the following problem:
[echo] Running tests ...
[exec] INSTRUMENTATION_RESULT: shortMsg=java.lang.ClassNotFoundException
[exec] INSTRUMENTATION_RESULT: longMsg=java.lang.ClassNotFoundException: pl.polidea.instrumentation.PolideaInstrumentationTestRunner in loader dalvik.system.PathClassLoader[/system/framework/android.test.runner.jar:/data/app/mj.geo.golf.application.test-1.apk:/data/app/mj.geo.golf.application-1.apk]
[exec] INSTRUMENTATION_CODE: 0
The manifest looks like:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mj.geo.golf.application.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<instrumentation
android:name="pl.polidea.instrumentation.PolideaInstrumentationTestRunner"
android:targetPackage="mj.geo.golf.application"
android:label="Tests for pl.polidea.somepackage" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<uses-library android:name="android.test.runner" />
</application></manifest>
I have looked around at other related posts and made sure that eclipse exports the the-missing-android-xml-junit-test-runner-release-1.3_2.jar and it appears in the workspace.
I am pretty new to android and java so any thoughts would be useful

You should read the Wiki more carefully.
The test runner should be added to the test project. Either as a .jar file (added in libs directory) or as external library (standard android external library approach). You can download the .jar file from here.
So the easiest way is to create a folder named libs just under the root of the project (the same level as src folder) and put the *the-missing-android-xml-junit-test-runner-release-1.3_2.jar* in it and then 'Add it to Build Path'.

Related

androidTest AndroidManifest.xml ignored

I have the same issue mentioned in this post AndroidTest Manifest permission not detected
and this post AndroidManifest in androidTest directory being ignored
--> If I put the test manifest in androidTest, debugAndroidTest, androidTestDebug, it never gets picked up and merged.
the answers about putting the AndroidManifest.xml in the debug folder are correct; that does seem to work. (put the test manifest in src/debug
What I want to know is why can't you put it in the androidTest directory? All the documentation I've read while trying to figure this out makes it sound like you should be able to, and that if you can't then I'm thinking that sounds like some bug in the manifest merger.
For what it's worth, I'm using Android Studio
That is correct and totally agree with you on the confusing documentation. The AndroidManifest.xml under androidTest* source sets would be packaged for the instrumentation APK that does your tests on your actual app APK. If you open the generated APKs for debug and androidTest under build/outputs/apk/ after compiling your app module with the command gradlew assembleDebugAndroidTest (assuming that you haven't changed the testBuildType in you build.gradle, more info here), you'll find that any AndroidManifest.xml configuration added under androidTest will be in the androidTest APK and not in your debug app APK.
And also as you said, in case you need test specific configurations like extra permissions, you'll have to place them in the AndroidManifest.xml under the debug source set instead of main, hence they'll only be available for testing your app but not in your release build. Of course you can always double check by opening the generated APKs after compiling to make sure that the configuration is right for each build variant.
If you need to add extra permissions for tests, you can do it.
You should set the same android:sharedUserId in default AndroidManifest.xml and androidTest/AndroidManifest.xml.
For example:
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:sharedUserId="com.yourpackagename.uid">
<application
android:label="#string/app_name"
android:roundIcon="#mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="#style/AppTheme"
tools:replace="android:allowBackup">
</application>
</manifest>
androidTest/AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:sharedUserId="com.yourpackagename.uid">
<uses-permission android:name="android.permission.***" />
</manifest>
For details: https://stackoverflow.com/a/14196493/3901000

Android-Tools Gradle Plugin 0.12 fails with error 'duplicated with element declared at AndroidManifest.xml'

I am struggling with a build error when using Gradle with the Android-Tools Gradle plugin to compile a multi-project build. 2 of my projects fail to build with the error reported above.
Note that we have added additional elements to the Android manifest that we use. Essentially, our AndroidManifest.xml file looks like this:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xxx.yyy.zzz"
android:versionCode="13"
android:versionName="1.2.3">
<uses-sdk
.../>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.xxx.yyy.CONFIGURATION"/>
<application
...>
<activity
...>
...
</activity>
<activity
...>
...
</activity>
</application>
<meta-data android:name="www" android:value="xxxx"/>
<meta-data android:name="xxx" android:value="yyyy"/>
<meta-data android:name="xxx" android:value="zzzz"/>
</manifest>
The error is being reported on the last 2 meta-data lines (at the bottom of the above example), where the android:name attributes are identical. My limited research has identified this to be valid XML. Unfortunately I have not been able to validate the schema as I understand that no schemas are published.
Extract from the build log:
:src:aaa:processDebugManifest
/xxx/aaa/src/main/AndroidManifest.xml:36:3 Error:
Element meta-data#xxx at AndroidManifest.xml:36:3 duplicated with element declared at AndroidManifest.xml:35:3
/xxx/aaa/src/main/AndroidManifest.xml/AndroidManifest.xml:0:0 Error:
Validation failed, exiting
:src:aaa:processDebugManifest FAILED
I have been using earlier versions of the Android-Tools Gradle Plugin with an identical Android manifest file and this has not caused an issue (last known working version 0.8).
Question: Can I add configuration to my build.gradle file to ignore this? Or would it be worthwhile raising as an issue on the Android-Tools repo?
Thanks

Could not find test class exception when running Android Junit

i am trying to run my test class as Android Junit Test through Eclipse and then its giving could not find test class excpetion.
I have properly mentioned the intrumentation target package to my productive code package.
Below is the android manifest
<?xml version="1.0" encoding="utf-8"?>
<uses-sdk android:minSdkVersion="15" />
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.abc.android" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<uses-library android:name="android.test.runner" />
</application>
I have also checked by build path, its properly including the target classes such that the class file could be found.
Not able to find what is the problem.
Thanks and Regards,
Saurav
I removed my project and got the latest version from my source code repo.
Then i ran my tests it did work.
But would like to know why the problem was there.
Where does Android junit test picks it classes when running from Eclipse ?...i presume its bin/classes which is in the build path...can not figure out on what is the problem
Did you check if you are setting up properly? See this link
http://developer.android.com/tools/testing/activity_test.html
Also you can think of using Robotium for testing.
https://code.google.com/p/robotium/

ClassNotFoundException, /mnt/asec

I´ve recently imported a project I knew was working before into Eclipse. After I try to install the project it says
09-13 11:55:43.628: E/AndroidRuntime(7880): Caused by: java.lang.ClassNotFoundException: cz.ursimon.heureka.client.android.prj.heureka.activity.MainActivity in loader dalvik.system.PathClassLoader[/mnt/asec/cz.ursimon.heureka.client.android-1/pkg.apk]
but I can´t find out what the problem is. First I thought it is the common problem with new ADT update, but I tried checking the PrivateLibraries in Order and Export according to other solutions, I cleaned my project several times and I can´t see anything wrong in my AndroidManifest file.
Anyone with a solution? :S
My AndroidManifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cz.ursimon.heureka.client.android"
android:installLocation="preferExternal"
android:versionCode="26062"
android:versionName="3.0"
>
<activity
android:name=".prj.heureka.activity.MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:launchMode="singleTask">
Try going to Project -> Properties -> Java Build Path -> Order & Export and ensure Android Private Libraries are checked for your project and for all other library projects you are using.
Clean all projects afterwards and Run your project
In your manifest file define the whole class path of your activity as below for your activity.
Also make sure your package defined is correct and in that pacakge your MainAcivity class resides.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cz.ursimon.heureka.client.android"
android:installLocation="preferExternal"
android:versionCode="26062"
android:versionName="3.0"
>
<activity
android:name="cz.ursimon.heureka.client.android.prj.heureka.activity.MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="#string/app_name"
android:launchMode="singleTask">
</manifest>

Android Unit Testing in Eclipse: "Failed to launch test"

I've just started trying to set up some unit testing in what is essentially my first android app. I've had a hell of a time finding resource for this, but ultimately was able to scrape together what I hoped was the right path forward.
First, this is what I've done.
In Eclipse, I right-clicked my project that I'd like to create a test project for.
I selected AndroidTools -> New Test Project
I filled out the necessary information selecting a location of ../MyApp/tests for the new project and selected MyApp as the project to test. Everything else was left as default.
While this was executing I received the below as an error:
[2011-04-01 08:13:02 - WPMSTest] R.java was modified manually! Reverting to generated version!
But everything seemed okay. I had a new source tree in my tests folder.
So I tried to execute it (first on hardware, then on the emulator) by RunAs -> Android jUnit test.
In both runs I received the below in my eclipse console:
[2011-04-01 08:23:04 - WPMSTest] Launching instrumentation android.test.InstrumentationTestRunner on device emulator-5554[2011-04-01 08:23:04 - WPMSTest] Failed to launch test
My two manifest files:
WPMSTest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.WPMS.test"
android:versionCode="1"
android:versionName="1.0">
<instrumentation android:targetPackage="com.WPMS" android:name="android.test.InstrumentationTestRunner" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<uses-library android:name="android.test.runner" />
</application>
WPMS:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.WPMS"
android:versionCode="1"
android:versionName="1.0">
<application android:label="#string/app_name" android:icon="#drawable/ic_launcher_wpms">
<activity android:name=".WPMS"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
I'm hoping someone has seen something like this before and can shed some light on what I'm doing wrong. Please let me know if you need any more files and I'll be sure to post them.
Thanks!
I was missing a TestSuite in my Test Project. Once I had my AllTests class extend TestSuite I got past the error.
For me the problem was that I was using JUnit 4. When I changed to JUnit 3 it started working. I hope this helps.
[2011-04-01 08:13:02 - WPMSTest] R.java was modified manually! Reverting to generated version!
You get this error when you manually make changes in the R.java file. At times, when you clean the project, R.java file goes missing. At such occasion you must either copy the same program's R.java(if stored somewhere as a copy) or create an entire new project.
For your second issue, I too have got similar error when I was testing my app on the device. I had to make changes in the shell using $adb. then the device got recognised.
I had the same problem: JUnit 3 TestCase works, but when running JUnit 4 TestCase, I got "Failed to launch test" error.
But after following Ken's suggestion, i.e. make the JUnit 4 test class extends TestCase, and rename the test method with the "test" prefix, the test launches and runs the test!

Categories

Resources