How to run unit tests with Android Studio

just add folder named instrumentTest under /src
it should have /java inside like this

enter image description here

then extend the class ActivityTestCase (or any other android unit-test-class), such as

package com.example.app.test;

import android.test.ActivityTestCase;

import junit.framework.Assert;


public class MainActivityTest extends ActivityTestCase {


public void testHappy(){
    Assert.assertTrue(true);
}

} 

right click on green java directory and select run all tests
and you should get this:

enter image description here

good luck

Leave a Comment