Robolectric test not running for project having own Application class - android

I have followed steps as mentioned Robolectric http://robolectric.org/eclipse-quick-start/
I am able to successfully run the test as per steps provided. For a fresh new Project and Test project.
But when I followed same steps for my existing project, then nothing happens only a warning is being shown and test gets terminated.
My existing app is for target android-15 and I am using robolectric-2.2-jar-with-dependencies.jar
P.S. I have created a new Java Project for my existing project.
UPDATE
After hours of debugging I found that, if I remove android:name="com.myapp.bl.MyApplication from AndroidManifest, then its starts executing tests.
<application
android:name="com.myapp.bl.MyApplication"
android:allowBackup="false"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
Is there any addition flag or setting, that I have to pass Robolectric, so that it
understands MyApplication class.
Regards,
Yuvi

I found the issue, there was an exception in MyApplication class. If that exception occurs then application was getting closed.

Related

Stetho, not seen inspect link

As you see in the picture, inspect link is not seen. I did steps in this answer:
https://stackoverflow.com/a/32173974/5118976
After I run application on the my phone but there is no inspect link. Why does this problem occur? How to solve?
Add
compile 'com.facebook.stetho:stetho:1.3.1'
in gradle file.
and confirm you added
Stetho.initializeWithDefaults(this);
in application class
I had same issues in android
I refer this line.https://github.com/facebook/stetho/issues/40
This is know issues .
After created the sqlite it does not work u want uninstall the app and install it will work .It worked for me.
Aside from creating the application class please make sure it's also added to the Manifest file. :)
<application
android:name=".App" // application class
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
...
...
/>

Eclipses does not seem to generate the correct Blank Activity android project

Hey guys I am new to Android development with eclipse. I am following the walkthrough on the google website (here) and already hit an issue with it. I've installed the SDK and eclipse as instructed. Now I am trying to create and run a default Blank Activity android app. When I create the project, eclipse creates an appcompat_v7 project along side my MyFirstApp project. When I hit run, the app seems to be build without any issues and the log tells mw that it is installed on my app. But nothing happens, and I can't find it on the device.
Now the reason I think that it is not getting generated is because that Android Manifest is very barebones and missing lots of vital things by the looks of it:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
</application>
Secondly, the next step in the tutorial asks me to open up the fragment_main.xml file from the res/layout/ directory. This file does not exist. The directory is empty, there is nothing there.
I don't get any errors so I am not sure what has gone wrong.
So after a long discussion with #Prodigga, we came to the point where we think it is better to take a step back and wait for things to settle with the new SDK release (api level 21).
By the way, tutorial in the question is not outdated. There is this minor problem with the new sdk.
I don't know what is causing the problem and I don't know the solution yet but there is a workaround. If you only want to create a blank activity, given that you are experiencing the same issue, do as follows
Uncheck "create activity" check box when configuring your new project.
Create the package and MainActivity manually.
Add it to the manifest manually.
If you would like to benefit from code auto-generation, then I recommend downgrading the sdk. For example, you could use this ADT bundle (10/30/2013 - Windows 64-bit), but don't try updating the SDK to level 21, not yet.
In your android manifest file, add an activity element as the child of the application element. Add the name of the Activity class that you would want to show on the launch screen. See the below link on the syntax for this:
http://www.mkyong.com/android/how-to-set-default-activity-for-android-application/

how to run android unit test project

I know this is silly question, but i am just stuck with this:
1.I have one main project called MainProject.
2. Inside that there is one test project which has its own source and menifest file and in menifest file i added all required to make it test project like this :
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.app.tests" android:versionCode="1"
android:versionName="1.0">
<application>
<uses-library android:name="android.test.runner" />
</application>
<uses-sdk android:minSdkVersion="3" />
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example.app" android:label="Tests for My App" />
</manifest>
Now i right click on it go to "Run As" and "Run Configuration" and select "Android JUnit Test" but it showing error:
MainProject does not specify a android.test.InstrumentationTestRunner instrumentation or does not declare uses-library android.test.runner in its AndroidManifest.xml
Any help plz?
There is one video link of #Lucifer below which is helpful and also my own answer which a link you can check which is also helpful.
Robotium is an Android test automation framework that has full support for native and hybrid applications. Robotium makes it easy to write powerful and robust automatic black-box test cases. With the support of Robotium, test case developers can write function, system and acceptance test scenarios, spanning multiple Android activities.
You can develop powerful test cases, with minimal knowledge of the application under test.
The framework handles multiple Android activities automatically.
Minimal time needed to write solid test cases.
Readability of test cases is greatly improved, compared to standard instrumentation tests.
Test cases are more robust due to the run-time binding to GUI components.
Fast test case execution.
Integrates smoothly with Maven or Ant to run tests as part of continuous integration.
select File/new/project
select Android Test Project
give the Project a name
select test target as the other project you already have, in your posting above "MainProject"
pick the target platform, ie Android 4.0
finish and the test project is made
add classes under src in the test project that extend one of the android.test classes
I am giving answer to my own question,rather it is not a answer it is a link that you can find which is very nice and easy to understand how you can do android unit test using Robotium
Here is the link: LINK

How do you reference classes in an Android library project

I am trying to fork my android app, and came upon a method thanks to my other question here using a library project. It is working fine enough for drawables and String assets. But now I've run into a problem.
I have a class (not an activity) which extends Application. I moved this class into my library project, and want to use it for the main application class in my two derived apps (works fine when directly in the main app).
Say my library is my.project.library and my app using the library is my.project
In the manifest for my.project I specified the following:
<application android:name="my.project.library.AppClass">
It compiles and deploys fine, but when I try to run it, it force-closes with the following exception:
11-15 03:14:25.707: E/AndroidRuntime(16800): java.lang.RuntimeException: Unable to instantiate application my.project.library.AppClass: java.lang.ClassNotFoundException: my.project.library.AppClass in loader dalvik.system.PathClassLoader[/data/app/my.project.apk]
From the drawables I also imported from the library, it seems that the library contents get in-lined into the main app. So I tried changing my manifest to:
<application android:name="my.project.AppClass">
but I still get the same error.
How can i reference a class in the library as my Application class in the main app?
Your original reference was correct.
That is:
<application android:name="my.project.library.AppClass">
Sounds like you not referencing the library project properly see http://developer.android.com/guide/developing/projects/projects-eclipse.html the Referencing a Library Project section.
I think you have not described the library that you are using in the manifest so you need to add something like this to the manifest.
<uses-library android:name="my.project.library" />

Android Eclipse Plugin: Instrumentation Test Runner not specified

I'm getting this error when trying to run unit tests from Eclipse with an Android Project. The list of Instrumentation Test Runners is empty in the Android preferences.
[2009-06-17 23:57:51 - MyApp] ERROR:
Application does not specify a
android.test.InstrumentationTestRunner
instrumentation or does not declare
uses-library android.test.runner
It's also annoyingly decided that because I tried to run a unit test once, that's what I always want to do.
You're probably missing the uses-library and instrumentation nodes in your AndroidManifest.xml:
<manifest ...>
<application ...>
<!-- ... -->
<uses-library android:name="android.test.runner" />
</application>
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="your.package"
android:label="your tests label" />
</manifest>
In the Run Configuration you may have Android JUnit Test, if there are any new launch configuration entries inside this, you delete it and then run your application it will run.
NOTE - This is likely to be the solution if you tried to run the test case before adding the correct lines to the manifest as described in the answer from Josef. If you have done this, delete the configuration (which will be complaining that no instrumentation test runner has been specified in its header) and then run it as an Android Junit Test again and it will create a valid configuration picking up the correct stuff that you have added to the manifest (see Josef's answer for this).
One thing I noticed in this discussion that might be tripping some people up is that you need to make sure the "instrumentation" element in your manifest is a child of "manifest" and not of "application." (The examples here are correct, but this easy to mix up.)
http://developer.android.com/guide/topics/manifest/instrumentation-element.html
If you put your instrumentation stuff inside application, it won't be picked up, and your choices in the Eclipse ADT plugin for instrumentation runner may be blank. (But no error is thrown or shown, etc.)
Just do a right click on your test class from eclipse IDE and click on "Run As". After this select "run Configuration" which will launch a Confiuration Window in eclipse and you need to click on the radio button next to the "Instrumentation Runner" and select the configured Instrumentation Runner from the drop down. Now click on apply and then click on Run .
I think this will solve your problem.
Thanks,
Smruti
It's not in your code, it's just eclipse is a little buggy. In your run configurations it could be trying to run a jUnit test, but select Run Application and that error will go away.
Besides ensuring that the below items are declared in the manifest of your test app, check in the Run Configuration that the "Instrumentation runner" field is set to
"com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner".
This what I ran into when figuring out why I test wouldn't run.
Manifest:
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="your.package"
android:label="your tests label" />
and...
<uses-library android:name="android.test.runner" />
The problem is when you created the project, you would have had a AVD, so these configuration would be missing. My suggested way is first create the AVD and then create the android project :).
If you would have already created the project and if does not have much code you have written I would suggest to delete it and create a new one.

Categories

Resources