我正在尝试在 Android Studio 中实现一个测试类来对 DBAdapter 进行一些测试。由于我需要在手机上运行测试才能使用数据库,因此我创建了一个 Instrumentation Unit Test(因为我尝试仅使用单元测试来完成它,但我需要使用数据库等等,并且那些只在本地运行)。
问题是当我尝试运行测试类时,使用我的手机作为运行设备,编译器抛出以下错误:
error: package org.junit does not exist
Run Code Online (Sandbox Code Playgroud)
我一直在寻找解决方案,但我没有找到。
这是我的测试类(只是骨架):
import org.junit.Test;
import android.support.test.runner.AndroidJUnit4;
import static org.junit.Assert.*;
public class DbAdapterTest {
@Test
public void testCreateSeries() throws Exception {
}
}
Run Code Online (Sandbox Code Playgroud)
这是 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 = …Run Code Online (Sandbox Code Playgroud) junit android unit-testing android-studio android-instrumentation