jeudi 24 mars 2016

Cannot run unit test for Android application

I am fairly new to unit testing and I am trying to create some unit tests for my application. After trying to follow some tutorials and videos, I keep getting the same error.

The error I'm getting in the console is

Running tests
Test running startedTest running failed: Unable to find instrumentation info for: ComponentInfo{com.example.noifcalculator.tests/com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner}
Empty test suite.

My build.gradle file has

apply plugin: 'com.android.application'

android {
    compileSdkVersion 19
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.example.noifcalculator"
        minSdkVersion 14
        targetSdkVersion 19
        testApplicationId "com.example.noifcalculator.tests"
        testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    sourceSets { main { java.srcDirs = ['src/main/java', 'src/androidTest/java'] } }
}

dependencies {
    compile 'com.android.support:support-v4:19.1.0'
    testCompile 'junit:junit:4.12'
}
android {
    defaultConfig {
        testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
    }
}

And my test file is fairly simple as well

public class CalculatorTest extends AndroidTestCase {
    MainActivity activity;
    public CalculatorTest() {
        super();
        activity = (MainActivity) getContext();
    }

    public void testNull() throws Exception {
        Button temp = (Button) activity.findViewById(R.id.btn_1);
        assertNotNull(temp);
    }
}    

Am I missing something obvious?

Aucun commentaire:

Enregistrer un commentaire