vendredi 1 avril 2016

Android Studio Junit tests package org.junit does not exist

I'm trying to implement a test class in Android Studio to make some test on a DBAdapter. Since I need to run the test on my mobile phone in order to use the database, I have created an Instrumentation Unit Test (cause I've tried to do it just with a Unit test but I need to use the database and so, and those are only run locally).

The problem is that when I try to run the test class, using my mobile phone as running device, the compiler throws the following error:

error: package org.junit does not exist

I've been looking for a solutione, but I found none.

This is my test class (just the skeleton):

import org.junit.Test;
import android.support.test.runner.AndroidJUnit4;

import static org.junit.Assert.*;


public class DbAdapterTest {

    @Test
    public void testCreateSeries() throws Exception {

    }
}

And this one is the build.gradle script:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.w2w.whattowatch"
        minSdkVersion 15
        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'
        }
    }
    testOptions {
        unitTests.returnDefaultValues = true
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    testCompile 'junit:junit:4.12'
    testCompile "org.mockito:mockito-core:1.9.5"
}

I also have another issue. As you can see, I also imported this:

import android.support.test.runner.AndroidJUnit4;

But, even before running, it says of "runner" that "cannot resolve the symbol". I've added the TestInstrumentationRunner on build.gradle, but still not working.

Aucun commentaire:

Enregistrer un commentaire