Android JUnit5整个项目的依赖关系

时间:2017-12-27 05:09:32

标签: android gradle junit

问题将JUint5附加到Android Studio中的即时应用项目。

研究在添加到每个要素的gradle文件时工作正常:

`dependencies {
  ...

  testCompile group: 'org.junit.jupiter',
              name: 'junit-jupiter-api',
              version: '5.0.0-M1'
  testCompile 'org.testng:testng:6.9.6'
}`

问题我可以为整个项目添加一次这些依赖项(Project Gradle或App Gradle和InstantApp Gradle)吗?

Project gradle:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.0.1'


    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}
}

allprojects {
repositories {
    google()
    jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}

基础gradle:

apply plugin: 'com.android.feature'

android {
  compileSdkVersion 26
  baseFeature true
  defaultConfig {
    minSdkVersion 21
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
  }
  buildTypes {
    release {
      minifyEnabled false
      proguardFiles getDefaultProguardFile(
        'proguard-android.txt'), 'proguard-rules.pro'
    }
  }
  defaultConfig {
    testInstrumentationRunner 
"android.support.test.runner.AndroidJUnitRunner"
  }
  compileOptions {
    targetCompatibility 1.8
    sourceCompatibility 1.8
  }
}

dependencies {
  api 'com.android.support:appcompat-v7:26.1.0'
  api 'com.android.support.constraint:constraint-layout:1.0.2'
  implementation 'com.android.support:design:26.1.0'

  application project(
    ':app')
  feature project(
    ':feature_navigate')

  testCompile 'org.junit.jupiter:junit-jupiter-api:5.0.0'
  testCompile 'org.testng:testng:6.13.1'
  testCompile 'junit:junit:4.12'

  testCompile 'org.mockito:mockito-core:2.13.0'

  androidTestCompile 'com.android.support:support-annotations:27.0.2'
  androidTestCompile 'com.android.support.test:runner:1.0.1'
  androidTestCompile 'com.android.support.test:rules:1.0.1'
  androidTestCompile 'org.hamcrest:hamcrest-library:1.3'
  androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.1'
  androidTestCompile  'com.android.support.test.uiautomator:uiautomator-v18:2.1.3'
}

1 个答案:

答案 0 :(得分:0)

这实际上是一个多项目Gradle构建问题doc reference

假设您在settings.gradle

中进行了项目设置
include "x", "y"
rootProject.name = 'root-folder'

项目布局如下:

|- root-folder
|- build.gradle
|- setting.gradle
|-- x
|-- y

然后,您可以将以下行添加到root-folder.gradle

allprojects {
  dependencies {
  ...

  testCompile group: 'org.junit.jupiter',
              name: 'junit-jupiter-api',
              version: '5.0.0-M1'
  testCompile 'org.testng:testng:6.9.6'
  }
}

它将适用于所有项目。

相关问题