SingleLaunchActivityTestCase cannot launch activity on test - android

I'm new in android testing. All I've used in the testing is only the ActivityInstrumentationTestCase2 (AITC2) which is explained in the Hello, Testing tutorial.
I've made a test class using AITC2 and it runs well. But once I changed the base test class to SingleLaunchActivityTestCase (SLATC) I got RuntimeException specifying "Unable to resolve intent.. blabla.." which I suspect was originated from launchActivity().
I thought AITC2 and SLATC are pretty much the same, besides that in SLATC the activity being tested only launched once (setUp() only launched once for all test cases) and in AITC2 the activity will be launced for every test cases.
I've tried to find some example or documentation about how to use SLATC but still no luck.. :(.
Anybody knows why the activity cannot be launched in SLATC? Thanks in advance :)

Solved it. I put a wrong package string in the constructor because I have several different subpackages in my project.
I put [package].activity, it should be only [package].
Kind of weird answering my own question, but just in case someone looking for an answer from the same mistake as mine.

Related

Exception when open Android N shortcuts

I am trying to implement Android N shortcuts but it crashes with an exception
android.content.ActivityNotFoundException: Shortcut could not be started. I believe its because I am not giving the correct targetPackageName in shortcuts.xml
I am not really sure what it should be pointing to if the application itself is in a different module and the activity I am trying to start is in a different module.
Any help is appreciated.
I had a similar problem recently. For me, the issue was that the Activity I was trying to launch only had an intent-filter for the LAUNCHER category. Once I created a separate intent filter that had category DEFAULT (ie, category android:name="android.intent.category.DEFAULT"), everything worked fine.
Note that if you're trying to use activities from different modules, it may be more flexible to use implicit intents. While your original approach will still work just fine, you may want to consider moving to using action constants instead of referring to the package name.
If that doesn't fix your problem, can you post your manifest and your shortcuts.xml?
Be sure TargetPackageName is Correct. Use package name where activity exist.
Use ActivityName like this:
android:targetClass="com.example.logs.ExampleActivity"
Use Package like this:
android:targetPackage="com.example.logs"
I Hope this works!!!

android robotium about the getCurrentActivity() delay

When I start an activity such solo.click(sth),
and then I am in a new activity. But when I run solo.getCurrentActivity(), the returning message is not the current one actually. It's the former one.
However, when I enter solo.getview(blablabla), and then run solo.getCurrentActivity(), it works again. I guess this is the waiting problem but I just don't know how to solve it. I've tried waitForActivity() and something similar but it doesn't work very well.
Do any one have suggestion?
Finally after several days I have found the answer. The solo.getCurrentActivity(yourAct,time) works. It's much safer than before now.

Android dalvikvm can't find/link to class

I've been working on an app for some time now and recently it keeps crashing on startup.
The error that causes it to crash is java.lang.ClassNotFoundException on my launcher activity. I've launched and debugged my app tons of times with no problems so I think I must've accidently changed something in a configuration file somewhere but I can't work out where.
I've checked the manifest file and there's nothing wrong, the path for the activity is correct and I've looked through the class file itself and again the package prefix is correct. I've also gone through the file directory and there's nothing wrong there either.
I tried changing the launcher activity to another one inside the same application and it runs with no problem, I've also tried creating a new launcher activity and that runs with no problem.
However, when I create a new activity and paste in all the code from the one that crashes the whole app crashes again. Even when the new activity has a different class name.
Also just before the app crashes I get two warnings:
Unable to resolve superclass of Lcom/bend/... and Link of class 'Lcom/bend/... failed
Now everything in my app is com.bend... NOT Lcom.bend... but I can't find anywhere where it's written Lcom. But I don't know if that's the cause of the problem or just a change the system does.
I know it's a real obscure problem but I just cannot figure it out. Any help would be awesome.
EDIT: I've just tried running another app I've done that's has a similar design and it's doing exactly the same thing.
I've just recently updated the SDK. Could that be the problem?
I've just solved it by creating an entirely new Android project and copying the java files and resources etc. into the new project.
I think it might have been the v4 support library that was causing the problem. I'm using a lot of Fragments so was relying heavily on it. Though I tried replacing the .jar file from an app that worked and it didn't seem to help...
In any case it was nothing to do with any of the classes or the manifest file.

Android Instrumentation Unit testing an adapter that requires a reference to an activity

I have inherited some messy code that I am trying to clean up. The first thing I'm starting with is writing some unit tests on the module's that I am planning on keeping for a while. Unfortunately, one of these is a custom adapter which requires a pointer to an activity (because it makes a call to getWindowManager() ). As soon as I started trying to write this test code, I immediately discovered a gap in my testing knowledge. How do I pass a pointer to an activity to the object I am testing?
I could launch a dedicated test activity? Should I be looking at the ActivityUnitTestCase instead of AndroidTestCase? All of these seem like messy solutions to what must be a relatively common problem? Does anyone know how to pass a pointer to an activity in android instrumentation testing without having that activity actually being the object under test?
Thanks in advance!!
Avtar
It seems that the correct way to do this is with AndroidUnitTestCase and use a dummy activity which your actual object being tested can point to. If anyone has any better suggestions let me know!

Android JUnit Test for Class

I am such a beginner in Android and I don't have any experience with JUnit. I am wondering if it is possible to directly use android api (ex. Camera.getNumberOfCameras()) inside the JUnit class. Actually, I have tried doing that although it compiled successfully, when I execute the test case I am getting ClassNotDefined error. Maybe I am missing something here.
Any feedback is greatly appreciated.
Thanks,
artsylar
Check out the documentation http://developer.android.com/guide/developing/testing/testing_eclipse.html#CreateTestProjectEclipse

Categories

Resources