jeudi 24 septembre 2015

Getting BUILD SUCCESSFUL but non of the test cases are getting executing in android studio

I am not getting where i am going wrong. Using android studio and trying to write test cases. I created a new project and the structure is :

-app
 -src
  -androidTests
   -java (com.example.testdemo.tests)
       - MainActivityTest 
  -main
   -java (com.example.testdemo)
       -MainActivity
   -res
   -AndroidManifest

I will go step by step :

1. build.gradle file content

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.example.testdemo"
        minSdkVersion 17
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testApplicationId "com.example.testdemo.tests"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.0.1'
}

  1. MainActivityTest.java

    import android.test.ActivityInstrumentationTestCase2;
    import android.test.suitebuilder.annotation.SmallTest;
    import android.widget.TextView;
    import com.example.webonise.testdemo.MainActivity;
    import com.example.webonise.testdemo.R;
    
    public class MainActivityTest extends ActivityInstrumentationTestCase2<MainActivity> {
    
    
    private TextView tv;
    private MainActivity mActivity;
    
    public MainActivityTest(Class<MainActivity> activityClass) {
        super(activityClass);
    }
    
    @Override
    public void setUp() throws Exception {
        super.setUp();
        mActivity = getActivity();
        tv = (TextView)mActivity.findViewById(R.id.tv);
        assertNotNull("Text view is null",tv);
    }
    
    public void testPreconditions(){
        assertNotNull("Text view is null",tv);
    }
    
    @SmallTest
    public void checkTextViewText(){
        String text = tv.getText().toString();
        assertEquals(mActivity.getResources().getString(R.string.hello_world), text);
    }
    
    @SmallTest
    public void checkTextViewText2(){
        String text = tv.getText().toString();
        assertEquals("fail", text);
    }
    }
    
    
  2. In studio Terminal i am giving this command: ./gradlew connectedCheck
    I am getting BUILD SUCCESSFUL but the report generated is showing this :


Test Summary 0 tests 0

failures

duration

successful Classes Class Tests Failures Duration Success rate


I appreciate you help.

Aucun commentaire:

Enregistrer un commentaire