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

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!

Related

APK not running on real device - Manifest error?

I am new on app's code. My project runs perfectly on emulators. However the apk is not running in my samsung device. Checking it with the Android Studio Analyzer the line xmlns:android="http://schemas.android.com/apk/res/android" in the manifest.xml returns in red. It seems that something is wrong with my project Manifest. Any Help? My manifest is copied below.
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0"
package="com.ferleecidade.a100dia11">
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="26" />
<application
android:theme="#ref/0x7f0f0005"
android:label="#ref/0x7f0e001f"
android:icon="#ref/0x7f0c0000"
android:debuggable="true"
android:exported="true"
android:allowBackup="true"
android:supportsRtl="true"
android:roundIcon="#ref/0x7f0c0002">
<activity
android:name="com.ferleecidade.a100dia11.MainActivity">
<intent-filter>
<action
android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.ferleecidade.a100dia11.MyCustomList" />
<meta-data
android:name="preloaded_fonts"
android:resource="#ref/0x7f020003" />
<meta-data
android:name="android.support.VERSION"
android:value="26.1.0" />
<meta-data
android:name="android.arch.lifecycle.VERSION"
android:value="27.0.0-SNAPSHOT" />
</application>
</manifest>
Help? Yes.
I am actively looking into this right now.
I don't believe your manifest is causing this or at least isn't the sole cause.
I have a project that I can run on my devices and emulators and deploy without a glitch.
I also get an error on the same line you do when analyzing the APK (Build/.Analyze APK).
If you hover your cursor over the red text you will see your error popup.
Mine says "URI is not registered (Settings | Languages and Frameworks | Schemes and DTDs)"
I performed a quick experiment.
created a brand new project in Android Studio with a single activity.
Cleaned the project.
Ran in an emulator.
Generated a signed APK.
Analyzed the APK and the error is there.
I suggest you try this.
This leads me to believe one of two things.
There is something wrong with my default project settings.
The error is being incorrectly reported by Android studio.
I hope this was useful.

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/

developing sony small apps on intellij idea?

I am a beginner at android, however I have tried developing simple android apps using IntelliJ idea. But when I tried developing sony small apps in IntelliJ idea, it does not work. When I try to run the application it say MainActivity is not a type of Activity.
My MainActivity extends SmallApplication provided by the Sony SDK.
Has anybody tried using sony small apps sdk with intelliJ idea or is there any work around for it to work..??
Just verify your code as below,
import android.app.Activity;
public class MainActivity extends Activity {
//Your body element
}
Extend Activity with you main activity
File -> Project Structure -> Libraries add and link to jar file
Then add the jar to the libs folder of your project so it is compiled with the apk. Otherwise it will not run on your device.
Ok, I figured our the everytime you click the run application button and choose a device, IntelliJ tries to install and app and start the main activity. So I set the run configuration to 'Do not Launch Activity', which helped solve my problem.
So now when I 'Run' my application, IntelliJ opens up the emulator and installs my app. Because Sony Small applications have to be run through a special application called SmallApps launcher, I manually run the application.
Small apps is a service NOT an activity. You need to edit the manifest and replace the activity to service ..see the correct manifest for small app:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.smallapp.example"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="15" />
<uses-permission android:name="com.sony.smallapp.permission.SMALLAPP" />
<application
android:icon="#drawable/ic_launcher" android:label="#string/app_name">
<uses-library android:name="com.sony.smallapp.framework" />
<service
android:name=".MainActivity"
android:exported="true" >
<intent-filter>
<action android:name="com.sony.smallapp.intent.action.MAIN" />
<category android:name="com.sony.smallapp.intent.category.LAUNCHER" />
</intent-filter>
</service>

Android/Sony Smartwatch: Unable to instantiate receiver (ClassNotFoundException)

I got an ClassNotFoundException with a static broadcastreceiver. The exception is fired when installing the app via eclipse on the device. I am developing an sony smartwatch extension, so I need to use the "SmartExtensionUtils" project from the sony sdk. As long as I was working inside the code example project everything was fine. I started a new project with Maven + Android and now it is no longer working!!! No idea why?!? I reckon something with the packages went wrong....
I got the following error:
E/AndroidRuntime(11201): java.lang.RuntimeException: Unable to instantiate receiver com.bla.move.smartwatch.sony.ExtensionReceiver: java.lang.ClassNotFoundException: com.bla.move.smartwatch.sony.ExtensionReceiver
My broadcastreceiver class is called ExtensionReceiver. The name inside the manifest file is the same ...
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bla.move.smartwatch.sony"
android:versionName="1.0" android:versionCode="1">
<uses-sdk android:minSdkVersion="7"/>
<uses-permission
android:name="com.sonyericsson.extras.liveware.aef.EXTENSION_PERMISSION" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name="SmartWatchPreferenceActivity" android:label="#string/preference_activity_title">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<service android:name=".SmartWatchExtensionService" />
<receiver android:name=".ExtensionReceiver">
<intent-filter>
.....
</intent-filter>
</receiver>
....
What could be the problem? Any suggestions??? I did alreday clean + rebuild (a couple of times)!
Did you include the SmartExtensionAPI and SmartExtensionUtil projects as dependencies, both in your project and in Maven?
Try cleaning the workspace (start Eclipse with the -clean flag), and make sure your project's JDK compliance settings is set to 1.6 (not 1.7)! That worked for me. I set the JDK compliance level of the whole workspace, instead of the project itself, and the error just disappeared!

Eclipse - new android activity showing in manifest but missing under src

I created a new blank activity from Eclipse's 'New' menu.
I didn't get any errors, and the activity looks to have been correctly populated in the manifest, however, no java class file has been created.
I get the impression that within Eclipse, the class should have been auto-created and auto-populated with the onCreate and onOptionsItemSelected method templates.
Why didn't Eclipse automatically create the class for me?
Manifest code as requested:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstandroidapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.myfirstandroidapp.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.myfirstandroidapp.DisplayMessageActivity"
android:label="#string/title_activity_display_message"
android:parentActivityName="com.example.myfirstandroidapp.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.myfirstandroidapp.MainActivity" />
</activity>
</application>
The fastest solution: keep the Activity in your manifest, but create the java class by right-clicking your package -> new -> class -> DisplayMessageActivity and then extend the Activity class and add the missing methods. Note that the class name have to match the one declared in the manifest
EDIT
After you've done it, clean the project by selecting project -> clean and check if there are any error messages left
I needed to uninstall Eclipse and install the sdk (adt bundle) from http://developer.android.com/ which comes bundled with eclipse to resolve this issue.
I found that my original set-up not only failed to create source files, but was also unable to create new android projects, even though it managed to create the first project successfully. Something must have happened to ruin the set up, no doubt, something I did but cannot trace.
What worked for me...
In eclipse, go to Help >
Install new software... > Work with: https://dl-ssl.google.com/android/eclipse/
Hit enter, checkmark "Developer Tools" and "NDK Plugins".
Let it download and install. I had to delete "myfirstapp" and remake it.
Restart Eclipse once it has downloaded and installed.
Having that issue and actually doing it over again helped me understand more about the syntax used in the lessons that I've already been through before.

Categories

Resources