Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make AndroidTest in android studio when it has deleted?

I have deleted AndroidTest in my project, but now I need that to test my project, how to create that?

like image 241
user3107610 Avatar asked Mar 23 '16 09:03

user3107610


People also ask

Can I delete Android test folder?

Yes You can delete them ,you can go to build. gradle and then remove following dependencies which comes preloaded in any new android project. and then click on the androidTest and Test package and Press Delete they will be removed !

Why use Android JUnitRunner?

The AndroidJUnitRunner class is a JUnit test runner that lets you run instrumented JUnit 4 tests on Android devices, including those using the Espresso, UI Automator, and Compose testing frameworks. Note: AndroidJUnitRunner is not needed for local tests.

How do I create a test in Android?

Open the 'Run...' menu and click 'edit configurations' Click the + button. Select the Android Tests template.


2 Answers

If your androidTest package has been deleted/not being shown, then do the following:

The best and easy way is to open your Android project in File Explorer (My Computer/Windows explorer in Windows OS )

Then go to app-->src

(There you will already find your main folder)

Now, create a new package/folder in app-->src and name it as androidTest

NOTE: the name is case sensitive. Type as shown above.

Now in you app-->src-->main folder, copy the java folder and paste it in app-->src-->androidTest folder.

Now in androidTest folder, open all the folder inside till the end and delete the existing java files.

Now in your Android Studio, you can clearly see the folder/package of androidTest made. Just add new Java file and write all the test code stuff there and its done.

like image 56
Akshay Chopra Avatar answered Oct 04 '22 20:10

Akshay Chopra


Just add a new java file in {root project dir}/app/src/androidTest/java/com/company/name

Android Studio will recognize it as AndroidTest.

package com.company.name;

import android.app.Application;
import android.test.ApplicationTestCase;

/**
 * <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
 */
public class ApplicationTest extends ApplicationTestCase<Application> {
    public ApplicationTest() {
        super(Application.class);
    }
}
like image 20
Tom Sabel Avatar answered Oct 04 '22 20:10

Tom Sabel