1

我的 build.gradle 是:

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'org.junit.platform.gradle.plugin'
apply plugin: 'io.qameta.allure'

defaultTasks 'clean', 'test'

ext.junitJupiterVersion = '5.0.0-M4'
ext.selenideVersion = '4.4.3'

compileTestJava {
    sourceCompatibility = 1.8
    targetCompatibility = 1.8
    options.encoding = 'UTF-8'
    options.compilerArgs += "-parameters"
}

compileJava.options.encoding = 'UTF-8'

tasks.withType(JavaCompile) {
    options.encoding = 'UTF-8'
}

repositories {
    jcenter()
    mavenCentral()
}

buildscript {
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.0-M4'
        classpath 'io.qameta.allure:allure-gradle:2.3'
    }
}

  allure {
    aspectjweaver = true
    autoconfigure = true
    version = '2.1.1'
}

  configurations {
    agent
  }

  dependencies {
    // JUnit5
    compile("org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}")
    compile("org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}")

    // Selenide
    compile("com.codeborne:selenide:${selenideVersion}") {
        exclude group: 'junit'
    }

    // Allure
    agent 'org.aspectj:aspectjweaver:1.8.10'
    compile 'ru.yandex.qatools.allure:allure-junit-adaptor:1.4.23'
    compile 'io.qameta.allure:allure-junit5:2.0-BETA6'
}

    junitPlatform {
platformVersion = "1.0.0-M5"
enableStandardTestTask = true
}

task runJupiter(type: JavaExec) {
jvmArgs '-ea'
jvmArgs "-javaagent:${configurations.agent.singleFile}"
classpath = project.sourceSets.test.runtimeClasspath
main 'org.junit.platform.console.ConsoleLauncher'
args '--scan-class-path'
args "--reports-dir=${buildDir}/allure-results"

finalizedBy 'allureReport'
}

test.dependsOn runJupiter

测试成功完成并自动创建三个文件夹:

{projectDir}\allure-results 与 .json 文件

{projectDir}\build\test-results\junit-platform 与 TEST-junit-jupiter.xml 文件

{projectDir}\build\reports\allure-report

我尝试通过 allure 命令行 (CLI) 在本地打开 .json 和 .xml 结果。魅力报告已打开但为空白: 这是报告视图

我想我在 gradle 依赖中的错误。我很困惑应该为 JUnit5+Allure2+Gradle+Selenide+Java8 使用哪些库和版本?

4

1 回答 1

1

JUnit Platform Gradle 插件当前不使用该test任务(它需要在 Gradle 核心中进行更改才能这样做)。因此,诸如此类test.doFirst {...}的事情不会起作用。

您应该能够创建自己的任务来运行ConsoleLauncher并在其中添加 JVM 代理,而不是使用插件。有关示例,请参见https://stackoverflow.com/a/43512503/6327046 。

于 2017-07-11T19:19:20.577 回答