Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Testing android app using Android Studio

Firstly I want to make a confession. I've never written a test before. I've been a programmer for more than 10 years, and never once I found the need to write a proper test (or whatever it is called) since mostly I write codes that (I think) can be easily tested manually.

Now I'm writing a pretty complex android app, and this manual testing I'm doing to make sure every functions and classes runs as intended slows me down miserably. So now I'm kinda searching in the dark on how to make my codes test-compatible (is there such a thing?) and where should I start.

I'm using the latest Android Studio (1.2 Beta 3). I found that under 'src' folder, there's an 'androidTest' folder, which (few folders beneath it) contains a file, ApplicationTest.java. Here's the content of ApplicationTest.java

public class ApplicationTest extends ApplicationTestCase<Application> {
    public ApplicationTest() {
        super(Application.class);
    }
}

Ok now back to my app. I want to test the class AnalyzerOffline.java (located under main>java>com.code.imin.app) that I've written, because it has pretty complex and large codes going around there. So how should I start? I tried reading http://developer.android.com/tools/testing/testing_android.html , http://rexstjohn.com/unit-testing-with-android-studio/ etc but I still don't know where to start - I feel like I'm missing something here, or maybe somehow my mindset of writing test or the whole idea of it are wrong.

So can please someone show me some light here?

like image 256
imin Avatar asked Apr 16 '15 14:04

imin


People also ask

How do you write test cases for Android apps?

Test cases should be written in such a way that they allow a person to test only one feature at a time. One should not overlap or complicate test cases. Cover all the positive and negative probabilities of the test outcomes. Write in simple language with exact and accurate names of forms, fields, etc.

How do I run an APK file in Android Studio?

Or, if you already have a project open, click File > Profile or Debug APK from the menu bar. In the next dialog window, select the APK you want to import into Android Studio and click OK. Android Studio then displays the unpacked APK files, similar to figure 1.


1 Answers

I am using Monkey tool testing

Step 1:

open the android studio terminal(Tools-> open terminal)

Step 2:

In order to use monkey , open up a command prompt and just naviagte to the following directory.

 export PATH=$PATH:/home/adt-bundle-linux-x86-20140702/sdk/platform-tools

Step 3:

add this monkey command into terminal and press enter..

see the magic in your emulator.

adb shell monkey -p com.example.yourpackage -v 500

500- it is the frequency count or the number of events to be sent for testing.

you can change this count..

More reference,

http://www.tutorialspoint.com/android/android_testing.htm

http://androidtesting.blogspot.in/2012/04/android-testing-with-monkey-tool.html

like image 192
Ranjithkumar Avatar answered Oct 12 '22 07:10

Ranjithkumar