android.support.test不存在,Android Studio Junit测试包org.junit不存在

在尝试使用Android Studio进行数据库测试时,作者遇到了一个错误:`error: package org.junit does not exist`。他们创建了一个InstrumentationUnitTest,因为单元测试无法直接访问数据库。在尝试运行测试时,编译器报错,同时`AndroidJUnit4`也无法解析。在build.gradle文件中已经包含了相关依赖,但问题仍然存在。作者寻求解决方案并分享了他们的测试类和build.gradle配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我正在尝试在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,但仍然无法正常工作.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值