Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用Android进行Spock测试_Android_Gradle_Spock - Fatal编程技术网

用Android进行Spock测试

用Android进行Spock测试,android,gradle,spock,Android,Gradle,Spock,我试图在我的android studio中运行spock测试,但我无法使其正常工作 我在modulegradle文件中添加了groovy和spock依赖项,并在项目构建gradle中应用了依赖项 我在运行spock测试时遇到的错误如下: Error:Execution failed for task ':app:compileDebugUnitTestGroovyWithGroovyc'. > Compilation failed; see the compiler error outpu

我试图在我的android studio中运行spock测试,但我无法使其正常工作

我在modulegradle文件中添加了groovy和spock依赖项,并在项目构建gradle中应用了依赖项

我在运行spock测试时遇到的错误如下:

Error:Execution failed for task ':app:compileDebugUnitTestGroovyWithGroovyc'.
> Compilation failed; see the compiler error output for details.
测试位于
src\test\groovy\
目录下

以下是模块级渐变文件:

apply plugin: 'com.android.application'
apply plugin: 'groovyx.android'

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.2'

    defaultConfig {
        applicationId "com.silverfix.dgdeditor"
        minSdkVersion 21
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets { main { java.srcDirs = ['src/main/java'] } }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile('junit:junit:4.12')
    compile 'org.spockframework:spock-core:1.1-groovy-2.4-rc-3'
    compile 'org.codehaus.groovy:groovy:2.4.9:grooid'
    compile 'com.android.support:recyclerview-v7:25.3.0'
    compile 'com.android.support:support-v4:25.3.0'
    compile 'com.android.support:design:25.3.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.1'
    compile 'com.android.support:appcompat-v7:25.3.0'
    compile 'com.stepstone.stepper:material-stepper:1.1.1'
    compile 'com.android.support:cardview-v7:25.3.0'
    compile 'jp.wasabeef:recyclerview-animators:2.2.5'
    compile 'com.github.barteksc:android-pdf-viewer:2.4.0'
    compile project(':javadgd')
    compile files('libs/commons-io-2.5.jar')
    compile files('libs/gson-2.8.0.jar')

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

buildscript {

    repositories {
        maven { url "http://dl.bintray.com/shivasurya/materialsteppers" }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'
        classpath 'org.codehaus.groovy:groovy-android-gradle-plugin:1.1.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven { url "http://dl.bintray.com/populov/maven" }
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
这是项目级的gradle文件:

apply plugin: 'com.android.application'
apply plugin: 'groovyx.android'

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.2'

    defaultConfig {
        applicationId "com.silverfix.dgdeditor"
        minSdkVersion 21
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets { main { java.srcDirs = ['src/main/java'] } }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile('junit:junit:4.12')
    compile 'org.spockframework:spock-core:1.1-groovy-2.4-rc-3'
    compile 'org.codehaus.groovy:groovy:2.4.9:grooid'
    compile 'com.android.support:recyclerview-v7:25.3.0'
    compile 'com.android.support:support-v4:25.3.0'
    compile 'com.android.support:design:25.3.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.1'
    compile 'com.android.support:appcompat-v7:25.3.0'
    compile 'com.stepstone.stepper:material-stepper:1.1.1'
    compile 'com.android.support:cardview-v7:25.3.0'
    compile 'jp.wasabeef:recyclerview-animators:2.2.5'
    compile 'com.github.barteksc:android-pdf-viewer:2.4.0'
    compile project(':javadgd')
    compile files('libs/commons-io-2.5.jar')
    compile files('libs/gson-2.8.0.jar')

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

buildscript {

    repositories {
        maven { url "http://dl.bintray.com/shivasurya/materialsteppers" }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'
        classpath 'org.codehaus.groovy:groovy-android-gradle-plugin:1.1.0'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven { url "http://dl.bintray.com/populov/maven" }
        jcenter()
    }
}

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

我试图在构建变体中更改测试工件,但没有找到该选项。

您在控制台中看到的输出是什么?根据您发布的“编译失败…”消息,您应该能够看到更多详细信息。鉴于您提供的配置,很难看到问题。但是,您可以在我的一个示例应用程序中找到正在运行的spock测试:。将此配置与您的配置进行比较可能会有所帮助。要执行测试,请使用
gradlew示例:testDebugUnitTest
,如果您可以提供实际的编译错误,我可以为您提供更多信息。但有几件事似乎不合适
sourceset{main{java.srcDirs=['src/main/java']}}
这是默认行为,为什么要添加它?Spock rc-3与byte buddy存在一些问题,建议更新到rc-4。Groovy 2.4.9有一个问题,我建议使用2.4.10。