How to test a project using instrumentation test in android - android

I want to test my project using an instrumentation test. I am a beginner at this.
Can anybody provide a basic tutorial for this?

Robotium is a great tool for testing Android app's you should take a look at it and it's very easy to use.
http://code.google.com/p/robotium/

To use ActivityInstrumentationTestCase2 we can create a wrapper over it. In order to do so you can try out example that this blog talks about.
testing Activities in simple way
The idea used is to take out common code in wrapper called BaseActivityTest so that while testing you just need to do minimum steps, and your activity gets tested too.

Related

Test Driven Development For Android

Can we use JUnit for test driven development in Android ? If not, is there an alternative similar to JUnit ?
I searched a bit on google and also read a SO post Android Test Driven Development
It looks like Android was never made with TDD in mind. I wanted to be sure before I begin learning TDD and doing Android development at the same time.
I think you can completely rely on Robolectric for running your tests in JVM. You get to use JUnit4 for testing your POJOs and Robolectric provides you the support for testing the Android components.
I am also a beginner in TDD for Android Development. I find Robolectric really useful for test driving my code.
This video will tell you almost everything it provides you for unit testing the Android code.
UPDATE:
With the Android studio support and the new Android ecosystem, now unit testing can be done as a first class practice. Refer http://developer.android.com/training/testing/unit-testing/local-unit-tests.html for more details.
There are couple of good approaches to test drive the android code. The most effective ones I have found so far is using MVVM(model-view-viewmodel) or MVP(model-view-presenter) approach, where the business logic as well as presentation logic is decoupled from the view and can be easily be unit tested.
Yeah we can use JUnit for test driven development. To initiate with you can refer to following
link : http://developer.android.com/tools/testing/testing_android.html#JUnit
Following the documentation we can use the junit.framework to have unit testing done.
Here is a bit of explanation of the problem space: http://www.techwell.com/2013/04/applying-test-driven-development-android-development
The conclusion is you should use Robolectric. Unfortunately Robolectric is slow, and if you follow TDD even on a pragmatic level, you will end up with a couple of hundreds of test, that will run for couple of 10 seconds. And that is not you want to do with TDD. TDD test package should run at most in seconds.
My advise is:
Create wrapper classes around Android classes that simply call the Android class.
Write your app logic in pure Java.
Use Junit (or TestNG or whatever pleases you) to test you model/business logic
Use occasionally Robolectric for the wrapper classes (probably you won't have to use)
(You can write integration tests that use multiple classes, Robolectric, etc. but only run it on a separate Continous Integration server eg. hourly)
With this approach your logic will be more portable as well.

Android: Automated GUI Testing

I would like to create some automated GUI tests for my android application. I am aware of Robotium and other similar projects but I would like to create my own testing framework from scratch. How can I achieve this?
You can begin by reading the documentation on testing and then taking a look at the source code for Robotium. That's how I would get started, at least.

Unit testing in Android apps. How should I go about it?

I have gone through this link.
But, there are just too many examples. What is the industry following? What are the best out there?
Also, is it a better idea writing my own unit tests using JUnit or the learning curve is too big for that?
There are many testing tools available in the industry but these are standard tools & methods
Robotium
Deviceanywhere http://www.keynotedeviceanywhere.com/mobile-application-testing-automation.html
perfecto mobile
here is the android official testing guide link
http://developer.android.com/guide/topics/testing/testing_android.html
use Junit for unit testing.
The common way is to begin with regular test cases for classes which doesn't dependent on android platform. After that you can test your db classes or something like it with AndroidTestCase or ActivityTestCase classes.
When the unit testing is done you can proceed to UI testing with Robotium.

Sample application for Android Tesing

I'm new to android testing. Can anybody please suggest me where I can get sample application along with test projects?
There's framework called
Robotium
http://code.google.com/p/robotium/wiki/Getting_Started
http://testdroid.com/tech/54/automated-ui-testing-android-applications-robotium
also
http://pivotal.github.com/robolectric/
http://pivotal.github.com/robolectric/user-guide.html
you might want to try it out.
Robotium is overkill for the moment, though you should remember it.
Start by reading the material regarding Testing in the Developers Guide. Its on the Dev Guide tab. One area at the bottom of Framework Topics, the other is under Developing.
There are two tutorials: Hello, Testing and Activity Testing. There's also a sample test project for the Note Pad sample app.
Of course, testing can mean many different things. I can't think of anything offhand that's for beginners. I know Beck's Test-Driven Development, and Working With Legacy Code (forgot the author, but you can Google it) for learning how to effectively unit test in OOP environments.
This should lead you in the right direction. It includes how to build a sample application and additional resources.

jUnit testing Database operations

I'm developing an Android application with database storage.
I want to test some classes that I use to access database.
I've found ActivityInstrumentationTestCase2 to test Activities but I haven't found anything to test classes.
How can I do that? I haven't used jUnit before.
Thanks.
I always use AndroidTestCases when writing unit tests for the Android platform. They provide access to a Context instance (if required), but otherwise work like the standard JUnit test class. You may also need to look at AndroidTestRunner to test your classes. There are some good tutorials out there; now that you know what to look for, I'm sure you can find them. Happy hunting! :D

Categories

Resources