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/
Related
Whenever I try to run my android app it shows the following error .
PowerSMS does not specify a android.test.InstrumentationTestRunner instrumentation or does not declare uses-library android.test.runner in its AndroidManifest.xml
What is the problem ? How can I solve this ?
Eclipse: Right click->Run As->Android Application instead of Android JUnitTest
Android Studio: Run->Edit Configuration to Run as Android Application either to device or emulator.
I think you probably missing the following in your AndroidManifest.xml:
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="your.package"
android:label="your tests label" />
and
<uses-library android:name="android.test.runner" />
I'm making fixes to an android application already on the market. When I imported the project all the map activities gave up errors. However, the map sections are working perfectly for the app on the market. I then added maps.jar to the libs folder. All the errors in the map activities disappeared. However when I ran the application the app crashed.
The logcat in this link
Here is the relevant part of the android manifest:
<application
android:allowBackup="true"
android:icon="#drawable/app_icon"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<uses-library
android:name="com.google.android.maps"
android:required="false" />
Thank you for your time. Any help is much appreciated.
The App is crashing because you have "java.lang.NoClassDefFoundError" in your main thread. Maybe you are missing a classpath or ClassPath attribute in your manifest. Please refer to this link. It has explanation of this error. Hopefully, you should be able to trace the cause of this error.
Hope it helped.
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>
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'.
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!