android - 设置 build.gradle Junit Android 测试

标签 android testing gradle junit

我是Android测试的初学者。我正在尝试执行 Junit 测试,但是当我加载 native 库时它会崩溃。

这是我的 build.gradle 文件:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"

    defaultConfig {
        minSdkVersion 18
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}


dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:24.0.0'
    // Unit testing dependencies
    testCompile 'junit:junit:4.12'
    // Set this dependency if you want to use the Hamcrest matcher library
    testCompile 'org.hamcrest:hamcrest-library:1.3'
    // more stuff, e.g., Mockito
    testCompile 'org.mockito:mockito-core:1.10.19'
}

repositories {
    flatDir {
        dirs 'libs'
    }
}

当我这样做时
static
    {
        System.loadLibrary("a");
    }

我得到java.lang.UnsatisfiedLinkError: no a in java.library.path
我的测试在 "src/test/java"和我的本地库 "src/test/jniLibs" .我想我必须在 build.gradle 中指定 Jni 库路径,但是如何?

谢谢

最佳答案

将文件夹添加到类路径中,如下所示:https://discuss.gradle.org/t/how-to-add-to-a-test-classpath/7083

关于android - 设置 build.gradle Junit Android 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38557113/

相关文章:

android - 在 XML 文件中使用图表引擎定位图形

android - TableRow 中的 TextView 部分隐藏

c# - Web 服务的快速和肮脏的性能测试 - 我有什么选择?

iphone - NSError 的单元测试

java - 使用 gradle 外包 java 包以便在其他项目中重用

java - Socket.IO Java 客户端到 Jar

android - InputConnectionWrapper 警告

testing - 如何在 NUnit 和 C# 中共享一个 Selenium webdriver 实例?

android - 具有公共(public)示例应用程序 gradle 设置的私有(private)源库

javascript - React-Native assembleRelease 任务 ':app:bundleReleaseJsAndAssets' 失败