Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android studio says "Empty Test Suite" for AndroidTestCase [duplicate]

I have created an example test case that extends AndroidTestCase. When I run the test case, it errors out by saying

Running tests
Test running startedTest running failed: 
Instrumentation run failed due to 'java.lang.RuntimeException'
Empty test suite.

The test case

import android.test.AndroidTestCase;
import android.test.suitebuilder.annotation.SmallTest;

import static org.junit.Assert.assertEquals;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;

import java.lang.Exception;
import java.lang.Override;

public class DateFormatTest extends AndroidTestCase{

    @Override
    protected void setUp() throws Exception {
        super.setUp();
    }

    @Override
    protected void tearDown() throws Exception {
        super.tearDown();
    }

    public DateFormatTest(){
        super(DateFormatTest.class);
    }


    @SmallTest
    public void testMultiply() {

        assertEquals("10 x 5 must be 50", 50, 10*5);
    }
}
like image 849
Pratik Mandrekar Avatar asked Dec 17 '13 14:12

Pratik Mandrekar


2 Answers

Since nobody else mentions it: methods in AndroidTestCase subclasses need to be public and have names starting with "test"!

The OP and the answers all got this right but I missed it and got the exact same error.

like image 179
Toerndev Avatar answered Nov 14 '22 16:11

Toerndev


I got this error when running tests from Android Studio. Turned out I had placed my test cases in the wrong folder. When running Gradle/Android Studio, all Android tests should be in the folder src/instrumentTest/java.

Edit: In Gradle plugin version 0.9 or later the correct name of the folder is androidTest. (http://tools.android.com/tech-docs/new-build-system/migrating_to_09)

like image 12
emidander Avatar answered Nov 14 '22 16:11

emidander