tsorn tsorn - 1 year ago 222
Android Question

Android JUnitRunner Empty Test Suite: No Test Results

I'm having trouble running tests in Android Studio. I've read through a load of posts with the same problem here on Stack Overflow, but to no avail. Just to be clear, I want to test in the emulator and not in the JVM.

Run configuration:



Running tests
Test running startedTest running failed: No test results
Empty test suite.


apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.0"

defaultConfig {
applicationId "ntnu.stud.markul.crowdshelf"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.0.1'
// Unit testing dependencies
androidTestCompile ('com.android.support.test:rules:0.3') {
exclude group: 'com.android.support', module: 'support-annotations'
androidTestCompile('com.android.support.test:runner:0.3') {
// Necessary if your app targets Marshmallow (since the test runner
// hasn't moved to Marshmallow yet)
exclude group: 'com.android.support', module: 'support-annotations'
androidTestCompile 'junit:junit:4.12'
testCompile 'junit:junit:4.12'

The test class (located in /src/androidTest/java/com/appname/app/):

public class NetworkAndDBInstrumentationTest extends ActivityInstrumentationTestCase2<MainActivity> {
private MainActivity mActivity;
public NetworkAndDBInstrumentationTest() {

public void setUp() throws Exception {

// Injecting the Instrumentation instance is required
// for your test to run with AndroidJUnitRunner.
mActivity = getActivity();

public void typeOperandsAndPerformAddOperation() {
Log.d("1TEST", "1TEST");

public void tearDown() throws Exception {

Answer Source

I got it to work using this:

public class NetworkAndDBInstrumentationTest {
    //use the following annotation and declare an ActivityTestRule for your activity under test
    public ActivityTestRule<RealmActivity> mActivityRule = new ActivityTestRule(RealmActivity.class);

    //use @Before to setup your test fixture
    public void setUp() {  }

    //annotate all test methods with
    public void testGetCrowd() {
        Assert.assertEquals(1, 1);
    public void tearDown() {  }

Where RealmActivity is the Activity I want to test. Build.gradle and everything else is as in the question post. Now, a follow-up question: What does it matter that I make the @Rule with RealmActivity? Can't I use other Activities in that test? Can I make a Activity-independent test?