在Travis CI中运行Android JUnit测试
我正在尝试使用Travis CI建立一个连续构建系统。到目前为止,我成功地在Travis上构建了我的Android项目,但当我尝试添加一个简单的单元测试时,构建失败了 我在Travis上遇到以下错误:“错误:包org.junit不存在” 这是我的,特拉维斯在Travis CI中运行Android JUnit测试,android,build,continuous-integration,travis-ci,Android,Build,Continuous Integration,Travis Ci,我正在尝试使用Travis CI建立一个连续构建系统。到目前为止,我成功地在Travis上构建了我的Android项目,但当我尝试添加一个简单的单元测试时,构建失败了 我在Travis上遇到以下错误:“错误:包org.junit不存在” 这是我的,特拉维斯 language: android android: components: - platform-tools - tools # The BuildTools version used by your project - build-to
language: android
android:
components:
- platform-tools
- tools
# The BuildTools version used by your project
- build-tools-23.0.2
# The SDK version used to compile your project
- android-23
# Additional components
- extra-google-google_play_services
- extra-google-m2repository
- extra-android-m2repository
# Specify at least one system image,
# if you need to run emulator(s) during your tests
# - sys-img-armeabi-v7a-android-21
- sys-img-armeabi-v7a-android-23
before_install:
- sudo chmod +x gradlew
env:
global:
# install timeout in minutes (2 minutes by default)
- ADB_INSTALL_TIMEOUT=8
# Emulator Management: Create, Start and Wait
before_script:
- echo no | android create avd --force --name test --target android-23 --abi armeabi-v7a
- emulator -avd test -no-skin -no-audio -no-window -gpu off -no-boot-anim &
- android-wait-for-emulator
- adb devices
- adb shell input keyevent 82 &
script:
- echo $ADB_INSTALL_TIMEOUT
- android list target
- ./gradlew clean
- ./gradlew assembleDebug
- ./gradlew assembleDebugAndroidTest
这是我的单元测试文件
package showcase.showcase;
import junit.framework.Assert;
import org.junit.Test;
import org.junit.Before;
import static org.junit.Assert.*;
public class SearchableActivityTest
{
SearchableActivity searchableActivity;
@Before
public void setUp() throws Exception
{
searchableActivity = new SearchableActivity();
}
@Test
public void searchQuesryTest() throws Exception
{
boolean result = searchableActivity.dummyTest();
assertTrue("Dummy function should return true", result);
}
}
你能告诉我我做错了什么以及如何修复它吗
编辑:
这是我的build.gradle(项目:Showcase)
这是我的build.gradle(模块:app)
单元测试在我的计算机上编译和运行,但在Travis上不起作用
谢谢如果您正在使用模拟器测试,请尝试此方法。 添加到依赖项部分的app build.gradle文件,因为您需要模拟器的库
// android emulator test dependencies
androidTestCompile 'junit:junit:4.12'
如果您正在使用仿真器测试,请尝试此方法。 添加到依赖项部分的app build.gradle文件,因为您需要模拟器的库
// android emulator test dependencies
androidTestCompile 'junit:junit:4.12'
请发布gradle脚本。你好,尼古拉,我刚刚添加了gradle文件。请在项目中查找重复的依赖项。如果你发现了,请在你的简历中使用
排除。你好,尼古拉,我在我的项目中没有发现任何重复。你知道我在哪里可以找到一个示例代码,我可以用它来设置我的Travis构建系统,以便在android上运行单元测试吗?请发布gradle脚本。你好,Nikola,我刚刚添加了我的gradle文件。在你的项目中查找重复的依赖项。如果你发现了,请在你的简历中使用排除。你好,尼古拉,我在我的项目中没有发现任何重复。你知道我在哪里可以找到一个示例代码,我可以用它来设置我的Travis构建系统,在android上运行单元测试吗?
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "showcase.showcase"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
}
// android emulator test dependencies
androidTestCompile 'junit:junit:4.12'