user
user

Reputation: 471

Write test case in Android application using Android Studio

I am working in Android app that is already developed and I need to write test case for this app in Android Studio. I want to know how to write test case in Android Studio ?

I also want to know what is main propose of writing test case? How to test app that we are writing write test cases?

I have made test folder

public class LoginActivityTest extends ActivityInstrumentationTestCase2<LoginActivity> {

private static final String LOGIN_DIALOG_FRAGMENT_TAG = NestAlertDialog.class.getSimpleName();

private LoginActivity mActivity;
private MainActivity mMainActivity;


public LoginActivityTest() {
    super(LoginActivity.class);
}

Upvotes: 1

Views: 2673

Answers (1)

Paul
Paul

Reputation: 158

I have made test folder

Atm(Android Studio 1.1.0) when you create a project AS takes care of creating a testing folder inside your app under /app/src/androidTest.

You can still create a test project directory elsewhere if you prefer, or you can try to follow the official website notes on testing.

I want to know how to write test case in android studio

I suggest you to start by downloading the sample code activityInstrumentation. From Android Studio, File -> Import Sample. Later you can check the documentation to develop further and more complicated test.

You can check this as further reference too.

What is main propose of writing test case

If your program is simple and does not goes beyond 100 LOC test case are probably useless, just the bigger the project gets the harder is to debug. You can have test cases for every tiny piece of code composing your application, thus ensuring that your entire application works correctly.

You can also write your application by writing its test cases before a single line of code as with Test Driven Development.

Upvotes: 1

Related Questions