- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试使用 Spock Framework
测试 Kotlin
类。当我的项目中只有 Java 类时,一切正常。但是在将 1.1.51
版本的 kotlin 添加到我的项目后,测试停止工作,现在我收到这样的错误:
Error:Execution failed for task ':app:compileDebugUnitTestGroovyWithGroovyc'.
> Cannot get property 'kotlinOutputDir' on null object
我正在使用 Android Studio 3.0 Beta 7
这是我的项目和模块 build.gradle
文件:
build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = '1.1.51'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.0.0-beta7'
classpath 'org.codehaus.groovy:groovy-android-gradle-plugin:1.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
classpath 'com.google.gms:google-services:3.1.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
build.gradle
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'groovyx.android'
android {
compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
applicationId "com.redione.debtscalc"
minSdkVersion 15
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.google.firebase:firebase-auth:11.4.2'
implementation 'com.google.firebase:firebase-database:11.4.2'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
testImplementation 'org.mockito:mockito-core:2.10.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
exclude group: 'com.android.support', module: 'support-annotations'
})
testImplementation 'org.codehaus.groovy:groovy:2.4.11:grooid'
testImplementation('org.spockframework:spock-core:1.1-groovy-2.4') {
exclude group: 'org.codehaus.groovy'
exclude group: 'junit'
}
}
apply plugin: 'com.google.gms.google-services'
repositories {
mavenCentral()
}
最佳答案
Groovy Android Gradle Plugin 发布了v2.0.0,兼容Android Gradle Plugin 3.0.0。编辑你的根 build.gradle
:
classpath 'org.codehaus.groovy:groovy-android-gradle-plugin:2.0.0'
原来的答案(不应该使用!),我留作历史用途。
简短的回答是,这个问题应该很快就会得到解决,目前正在进行中的 Groovy Android Gradle 插件 v2.0.0。
较长的答案(立即得到返回)是您可以按如下方式解决此问题。参见 my comment关于 Github 上的问题。
应将以下内容添加到 app/build.gradle
:
// Ugly workaround for incompatibility between Groovy Android Gradle Plugin 1.2.0 and Android Gradle Plugin 3.0.0
// Should be fixed with Groovy Android Gradle Plugin 1.3.0. https://github.com/groovy/groovy-android-gradle-plugin/pull/155
task copyFlavorDebugUnitTestKotlinClasses(type: CopyKotlinClasses)
class CopyKotlinClasses extends DefaultTask {
def kotlinOutputDir = ["$project.rootDir/app/build/tmp/kotlin-classes/flavorDebugUnitTest"]
@TaskAction
def doNothing() {
}
}
请注意,您必须将“flavor”替换为您项目的实际 flavor ,如果您不使用产品 flavor ,则将其删除。
关于android - 无法在空对象上获取属性 'kotlinOutputDir' - Kotlin 和 Spock,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46731894/
在特征方法中,在 when: 中指定特征 Action 。块,其结果在后续 then: 中得到测试堵塞。通常需要准备,这在 given: 中完成条款(或 setup: 或夹具方法)。包含前提条件同样有
我尝试使用 Spy 测试但没有成功。下面的类是一个 Sut。 public class FileManager { public int removeFiles(String director
我希望能够在运行一些自动化测试时记录 spock 功能名称和子句标签。这将有助于在使用 headless 浏览器进行自动化时调试测试问题,特别是 phantomjs。原因是,phantomjs 的行为
如何以编程方式跳过 Spock 框架中的测试?我知道我可以 annotate a test with @Ignore 跳过它,或使用 @IgnoreIf跳过基于环境变量等的测试。但是有没有办法运行任意
下周我将做一个关于 Spock 的演讲,作为演讲的一部分,我需要做一个演示。我以前在一个项目中使用过 Spock,但大约一年左右没有使用它。 演示需要不仅仅是“hello world”类型的演示。我正
下周我将做一个关于 Spock 的演讲,作为演讲的一部分,我需要做一个演示。我以前在一个项目中使用过 Spock,但大约一年左右没有使用它。 演示需要不仅仅是“hello world”类型的演示。我正
为简单起见,我们来看一个非常简单的类: public class TestingClass { public void method1(){ System.out.printl
Spock 只允许从 where 块访问静态变量。 是否有任何解决方法可以在 where 块中使用哪些实例变量? 最佳答案 您可以使用 @Shared 注释实例变量,见 http://spockfra
我正在使用 Spock 框架进行测试,一切都很好,直到今天;我不知道发生了什么。 Intellij 说“配置 Groovy sdk”所以我下载了 groovy sdk 2.4.9 并配置了它,但是在我
我正在为 grails 2.1.1 应用程序的一组现有测试添加第一个 spock 集成测试。使用以下方法运行时,测试运行和测试通过: grails test-app integration:spock
我过去曾在其他项目中使用旧版本的 robolectric 使用 robospock 和 electricspock 对 robolectric 进行过 spock 测试。我的新项目使用 robolec
我正在使用 Maven Surefire 插件运行一组 Spock 测试作为集成测试用例。我知道我们可以使用 @Shared 关键字在单个文件中跨规范的固定装置共享资源。 但是,是否可以在不同的规范文
我正在与: Spock 核心 史波克报告 斯波克 Spring Spring MVC 测试 我有以下代码: def "findAll() Expected"(){ given: "The UR
我正在与: Spock 核心 史波克报告 斯波克 Spring Spring MVC 测试 我有以下代码: @FailsWith(java.lang.AssertionError.class) def
我正在为我的插件创建 Spock 测试 project-plugin我的主要项目名称是 main-project正在使用 project-plugin作为插件。因此,当我为我的插件创建 Spock 测
在JUnit 3中,我可以这样获得当前正在运行的测试的名称: public class MyTest extends TestCase { public void testSomething(
我有一些类似Java的东西: public interface EventBus{ void fireEvent(GwtEvent event); } public class SaveCom
在我的测试中,我有一些只需要在特定情况下运行的特征方法。我的代码看起来像这样: class MyTest extends GebReportingSpec{ def "Feature meth
在我的测试中,我有一些只需要在特定情况下运行的特征方法。我的代码看起来像这样: class MyTest extends GebReportingSpec{ def "Feature meth
我遇到的问题是当我尝试在 then 中验证时阻止已抛出异常,并且已进行模拟调用。 看看下面的设置: class B { def b(A a) { a.a() } } c
我是一名优秀的程序员,十分优秀!