如何运行使用' WithTagValuesOf'注释的特定测试?使用SerenityRunner和Gradle

时间:2016-09-15 15:32:54

标签: gradle serenity-bdd

我正在尝试使用' WithTagValuesOf'来运行一组特定的junit测试。由Serenity-BDD框架提供。

根据Serenity教程,我可以找到与Maven相同的内容:

mvn clean verify -Dtags="release:sprint-2"

但我正在尝试为Gradle找到类似的方法。例如:

gradle clean test --tests -Dtags="Test-Type:Smoke" aggregate

上面给出了以下错误:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':test'.
> No tests found for given includes: [tags=Test-Type:Smoke]

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

我一发布这个问题就找到了答案(我的不好)

我对针对JBehave实现的类似问题提供的解决方案进行了调整。感谢Shawn Boyle的参考https://groups.google.com/d/msg/thucydides-users/IFwX64zuFSw/vC_43Nl_C84J

以下是我添加到构建文件中的代码。

的build.gradle:

task copyPropsFile << {
    if(!project.hasProperty('environment')){
        ext.environment = 'dev'
    }

    copy{
        from '../conf/' + environment + '/properties/serenity.properties'
        into projectDir
    }

    if (project.hasProperty('tags')) {
        println "JUnit tags set to: $tags"

        ant.propertyfile(file: "$projectDir/serenity.properties") {
            entry(key: "tags", value: "$tags")
        }
    }
}

// Hook into the gradle processTestResources task to execute the copyPropsFile custom task
processTestResources{
    doFirst{
        copyPropsFile.execute()
    }
}

最后我使用

运行我的测试
gradle clean test aggregate -Ptags="Test-Type:Smoke"