【问题标题】:How to get test name of GebReportingSpec in setup如何在设置中获取 GebReportingSpec 的测试名称
【发布时间】:2015-06-26 13:05:47
【问题描述】:

我正在使用 GebReportingSpec。 我想获取将使用 setup 方法执行的测试名称。 我从testName.methodName 得到空输出 我的代码 sn-p 如下:

class CRMAppLoginSpec extends GebReportingSpec {
@Rule
public TestName testName = new TestName()

setup()
{
   String methodName = testName.methodName;     
   println (methodName)
}
def "mytest"(String myName)
{
    given: "This is my test case in geb-spock"


    when: "capture the parameter"
    def var1 = myName

    then: "Display input parameter"
    println ("Welcome to geb-spock : ${var1}" )

    where:
    myName << ["Debasish", "Prashant"]
}

【问题讨论】:

标签: spock


【解决方案1】:

您可能应该从运行的代码开始。

查看有关在每个测试中处理错误的答案,它将向您展示如何在测试生命周期的每个阶段执行某些操作。 Answer

如果您尝试改进控制台报告,最好使用 Spock 的 AbstractRunListener。 Check this out

您有迭代,其中每个方法名称都是相同的,您可以使用 @Unroll 注释来区分它们。

class TestSpec extends GebReportingSpec {
    @Rule
    public TestName testName = new TestName()

    def setup() {
        String methodName = testName.methodName;
        println(methodName)
    }

    @Unroll("Iteration: mytest #myName")
    def "mytest"() {
        given: "This is my test case in geb-spock"

        when: "capture the parameter"

        then: "Display input parameter"
        println("Welcome to geb-spock : ${myName}")

        where:
        myName << ["Debasish", "Prashant"]
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-18
    • 2015-10-11
    • 1970-01-01
    • 1970-01-01
    • 2020-01-16
    • 1970-01-01
    • 2022-12-25
    • 1970-01-01
    相关资源
    最近更新 更多