Android JUnit Test for Class - android

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

Related

I can't run Realm project with android studio

Hi every one could you please help me to fix that error:
I use android studio so i found this: https://github.com/realm/realm-java/tree/rw-performance-comparison
So my probleme is : I can't run this project I really tried a lot of time before asking you.
Christian from Realm here.
You are trying to compile an old branch that is not maintained anymore. If you are interested in performance numbers I would encourage you to write your own performance test. Then you would also be able to test the stuff you care about instead of looking at generalised numbers.

Android studio test package won't autocomplete

I'm using android studio and have been able to properly import Robolectric.
When writing code in the test class it responds as though I'm simply using a textEditor.
To give an example of my problem: When I create a POJO I am able to give the constructor a the wrong arguments and the IDE doesn't respond at all.
And i do have the correct POJO import.
Powersave mode!
Put it off and your ide will work as usually ;)

How to use the AndroidTestCase file?

I'm working on some stuff and some nice guy give me these link. It is an AndroidTestCase file. I've done some seach, it seems that this has something to do with the TestSuit. I also read stuff about the android test frame. But there is no clear information about how could I build a test based on this AndroidTest file. Can anyone give me a hint?
Thank you!

Toast message only in Testing

I am android newbie.
I made a simple program, and I used Toast code for checking if variable is correct or not. After finishing test, I have to remove all the Toast code to release app. I think there must be more effective and better way to do this.
please help me
thank you in advance.
Use LogCat. You can output values to LogCat output using Log.d in your code. You can read detailed information about LogCat and logging here Debugging in Android using Eclipse
If you use ant, you can have define some parameter like build.debug in build.properties files, you will need to have two different files build_dbg.properties and build_rel.properties.
I would extend the Log class and redirect everything to android.Log.
In your own implementation you can then fire the Toast.
You will need to pass the Context and maybe execute it on UI thread.
If you use Log.[vdiwe], you should consider to use Androlog. It does the same as the default android Log class, but you can switch it of when you release your app later on.
It also supports some kind of reporting mechanism, which I did not test up to now, but looks promising.
I’ve never bothered with the Log class, because I found that everything written to System.err appears in the Android log regardless.

SingleLaunchActivityTestCase cannot launch activity on test

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.

Categories

Resources