gpt4 book ai didi

unit-testing - 使用来自终端的gradle for CI进行单元测试

转载 作者:行者123 更新时间:2023-12-03 04:40:44 25 4
gpt4 key购买 nike

我一直在尝试在Android Studio和Gradle中使用单元测试,但是现在我集中精力使用./gradlew测试进行所有测试。问题是我从项目中的库中收到以下错误:

/Users/Radsen/Projects/Mobile/AllianceTech/androidstudio/ATDroidUtils/app/src/test/java/com/alliancetech/ileadsalpha/ITEventsAPI.java:20: error: cannot find symbol
private MockContext context;
^
symbol: class MockContext
location: class ITEventsAPI
/Users/Radsen/Projects/Mobile/AllianceTech/androidstudio/ATDroidUtils/app/src/test/java/com/alliancetech/ileadsalpha/ITAssociationAPI.java:19: error: cannot find symbol
RestClient rcAssociationsByEventID = new RestClient("");
^
symbol: class RestClient
location: class ITAssociationAPI
/Users/Radsen/Projects/Mobile/AllianceTech/androidstudio/ATDroidUtils/app/src/test/java/com/alliancetech/ileadsalpha/ITAssociationAPI.java:19: error: cannot find symbol
RestClient rcAssociationsByEventID = new RestClient("");
^
symbol: class RestClient
location: class ITAssociationAPI
/Users/Radsen/Projects/Mobile/AllianceTech/androidstudio/ATDroidUtils/app/src/test/java/com/alliancetech/ileadsalpha/ITEventsAPI.java:30: error: cannot find symbol
RestClient rcLeadsByEventID = new RestClient(base_url + "/rest/event/" + EVENT_ID);
^
symbol: class RestClient
location: class ITEventsAPI
/Users/Radsen/Projects/Mobile/AllianceTech/androidstudio/ATDroidUtils/app/src/test/java/com/alliancetech/ileadsalpha/ITEventsAPI.java:30: error: cannot find symbol
RestClient rcLeadsByEventID = new RestClient(base_url + "/rest/event/" + EVENT_ID);
^
symbol: class RestClient
location: class ITEventsAPI
/Users/Radsen/Projects/Mobile/AllianceTech/androidstudio/ATDroidUtils/app/src/test/java/com/alliancetech/ileadsalpha/ITEventsAPI.java:38: error: cannot find symbol
RestClient rcTagsCode = new RestClient(base_url + "/rest/event/tags");
^
symbol: class RestClient
location: class ITEventsAPI
/Users/Radsen/Projects/Mobile/AllianceTech/androidstudio/ATDroidUtils/app/src/test/java/com/alliancetech/ileadsalpha/ITEventsAPI.java:38: error: cannot find symbol
RestClient rcTagsCode = new RestClient(base_url + "/rest/event/tags");
^
symbol: class RestClient
location: class ITEventsAPI
/Users/Radsen/Projects/Mobile/AllianceTech/androidstudio/ATDroidUtils/app/src/test/java/com/alliancetech/ileadsalpha/ITEventsAPI.java:46: error: cannot find symbol
RestClient rcLeadEventsByTag = new RestClient(base_url + "/rest/eventtag/" + TAG + "/events");
^
symbol: class RestClient
location: class ITEventsAPI
/Users/Radsen/Projects/Mobile/AllianceTech/androidstudio/ATDroidUtils/app/src/test/java/com/alliancetech/ileadsalpha/ITEventsAPI.java:46: error: cannot find symbol
RestClient rcLeadEventsByTag = new RestClient(base_url + "/rest/eventtag/" + TAG + "/events");

这是我的build.gradle
apply plugin: 'com.android.application'

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "com.alliancetech.ileadsalpha"
minSdkVersion 15
targetSdkVersion 20
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
productFlavors {
}

sourceSets {
instrumentTest.setRoot('src/test')
}
}

sourceSets {
unitTest {
java.srcDir file('src/test')
resources.srcDir file('src/test/resources')
}
}

configurations{
unitTestCompile.extendsFrom runtime
unitTestRuntime.extendsFrom unitTestCompile
}

dependencies {
compile 'junit:junit:4.12'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:6.5.87'
compile 'com.googlecode.json-simple:json-simple:1.1'
compile 'org.roboguice:roboguice:2.0'
compile project(':atdroidutilslib')

//unitTestCompile 'junit:junit:4.12'
//unitTestCompile 'com.googlecode.json-simple:json-simple:1.1'
unitTestCompile "org.apache.httpcomponents:httpmime:4.2.3"
unitTestCompile project(':atdroidutilslib')
}

task iLeadsIntegrationTests(type:Test, dependsOn: assemble) {
testClassesDir = project.sourceSets.unitTest.output.classesDir
classpath = project.sourceSets.unitTest.runtimeClasspath
}
check.dependsOn iLeadsIntegrationTests

最佳答案

在工作了将近2天之后,我决定重试我看到的一些帖子,而这个帖子帮助我解决了我的问题。链接在这里:
http://tools.android.com/tech-docs/unit-testing-support

关于unit-testing - 使用来自终端的gradle for CI进行单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28414719/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com