我正在尝试在Android Studio中实现一个测试类,以便对DBAdapter进行一些测试.由于我需要在手机上运行测试才能使用数据库,因此我创建了一个Instrumentation Unit Test(因为我试图仅通过Unit test来进行测试,但是我需要使用数据库,如此,这些仅在本地运行).
问题是,当我尝试使用手机作为运行设备来运行测试类时,编译器会引发以下错误:
error: package org.junit does not exist
我一直在寻找解决方案,但没有找到.
这是我的测试课(只是骨架):
import org.junit.Test;
import android.support.test.runner.AndroidJUnit4;
import static org.junit.Assert.*;
public class DbAdapterTest {
@Test
public void testCreateSeries() throws Exception {
}
}
这是build.gradle脚本:
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"
}
我还有另一个问题.如您所见,我还导入了此代码:
import android.support.test.runner.AndroidJUnit4;
但是,甚至在运行之前,它还说“运行器”“无法解析符号”.我在build.gradle上添加了TestInstrumentationRunner,但仍然无法正常工作.