kre*_*eek 7 junit android intellij-idea gradle android-gradle-plugin
我在的IntelliJ一个测试项目(使用Android Studio的插件)和我试图描述设置单元测试在这里.
运行junit测试时,项目似乎无法在src> main> java下找到我的源代码.以下测试
package io.adaptiv.plzwrk.lib;
import junit.framework.TestCase;
import org.junit.Test;
public class AdaptivTest extends TestCase {
@Test
public void testDoStuff() throws Exception {
assertEquals(42, Adaptiv.doStuff());
}
}
Run Code Online (Sandbox Code Playgroud)
给出了错误
error: cannot find symbol
assertEquals(42, Adaptiv.doStuff());
^
symbol: variable Adaptiv
location: class AdaptivTest
Run Code Online (Sandbox Code Playgroud)
我的'测试'课程
package io.adaptiv.plzwrk.lib;
public class Adaptiv {
public static int doStuff() {
return 42;
}
}
Run Code Online (Sandbox Code Playgroud)
我的项目布局看起来像这样

使用settings.gradle
include ':lib'
Run Code Online (Sandbox Code Playgroud)
项目build.gradle文件
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.1'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
jcenter()
}
}
Run Code Online (Sandbox Code Playgroud)
lib目录下的build.gradle
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.1.1'
}
}
apply plugin: 'com.android.library'
repositories {
jcenter()
}
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
minSdkVersion 9
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
testCompile 'junit:junit:4.12'
testCompile "org.mockito:mockito-core:1.9.5"
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1012 次 |
| 最近记录: |