Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test run failed: Test run failed to complete. Expected 1 tests, received 0

I tried starting a JUnit test (robotium) for my app:

public class MainTest extends ActivityInstrumentationTestCase2<MainActivity> {
    private Solo solo;

    public MainTest() {
        super("nix.android.contact", MainActivity.class);// TODO Auto-generated constructor stub
    }

    protected void setUp() throws Exception {
        super.setUp();
        solo = new Solo(getInstrumentation(), getActivity());
    }

    public void AddContact() {
        solo.assertCurrentActivity("main", MainActivity.class);
    }
}

Manifest

 <instrumentation
    android:name="android.test.InstrumentationTestRunner"
    android:targetPackage="nix.android.contact" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <uses-librar

y android:name="android.test.runner" />
    </application>

When I try to run the test this is the error I get in the console:

Test run failed: Test run failed to complete. Expected 1 tests, received 0

I tried creating another test a different app (very simple app) and it works.

like image 630
Alex Avatar asked Jul 24 '12 22:07

Alex


3 Answers

I had this problem when I didn't have a no-args constructor.

public class MainActivityTest extends
    ActivityInstrumentationTestCase2<MainActivity_> {

public MainActivityTest() {
    super(MainActivity_.class);
}
...
like image 169
koljaTM Avatar answered Nov 16 '22 09:11

koljaTM


I had the same issue while running instrumentation tests on Android (@RunWith(AndroidJUnit4.class)).

I had the following error:

Tests on Nexus_5X_API_26(AVD) - 8.0.0 failed: 
Test run failed to complete. Expected 156 tests, received 152

The problem was that one of the test classes was failing inside a method marked with @BeforeClass, hence no tests were executed for that particular class. Moreover that, the exception which was thrown inside @BeforeClass didn't end-up in the tests-output/report. That's why it was hard to find a reason of "Expected N tests, received M" error message.

So, if you run into the same issue - check your @Before and @BeforeClass implementations - an exception there could be the reason. Hope this helps.

like image 38
Ch3D Avatar answered Nov 16 '22 08:11

Ch3D


The problem is in your call at

super("nix.android.contact", MainActivity.class);

In my code I have

super("nix.android.contact", Class.forName("nix.android.contact.MainActivity"));

I've also done it this way without have to name the Generic for the ActivityInstrumentationTestCase 2

public class TestApk extends ActivityInstrumentationTestCase2 {

    private static final String TARGET_PACKAGE_ID = "nix.android.contact";
    private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "nix.android.contact.MainActivity";

    private static Class<?> launcherActivityClass;
    static{
            try {
                    launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
            } catch (ClassNotFoundException e) {
                    throw new RuntimeException(e);
            }
    }

    @SuppressWarnings("unchecked")
    public TestApk() throws ClassNotFoundException {
            super(TARGET_PACKAGE_ID, launcherActivityClass);
    }
like image 1
JPM Avatar answered Nov 16 '22 09:11

JPM