Groovy的。使用动态名称进行参数化测试

时间:2017-08-17 21:50:11

标签: unit-testing dynamic groovy junit parameter-passing

我想实现groovy参数化测试,其中测试名称将使用参数值构建。我知道如何在java中执行此操作(我也找到了java回答here,但没有找到groovy

所以我需要用相同的选项改进我的groovy参数化单元测试:

import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized

@RunWith(Parameterized)
class TestSimple {

    String numberA
    String numberB
    String expectedResult

    TestSimple(numA, numB, expected) {
        numberA = numA
        numberB = numB
        expectedResult = expected
    }

    @Parameterized.Parameters
    static data1() {
        [
                [null, "asd|asd|||ASD||ASD", 'result for first case'],
                ['09909', "asd|asd|||ASD||ASD", 'result for second case']

        ]*.toArray()
    }

    @Test
    void testLogonRequest1() throws Exception {
        println numberA + ":" + numberB
    }
}

用参数值

替换有序数字
TestSimple
  [0]
    testLogonRequest1[0]
  [1]
    testLogonRequest1[1]

预期结果类似于:

TestSimple
  [used parameters: <numberA0value>, <numberB0value>]
    testLogonRequest1[expected result: <expectedResult0Value>]
  [used parameters: <numberA1value>, <numberB1value>]
    testLogonRequest1[expected result: <expectedResult1Value>]

有什么想法吗?

0 个答案:

没有答案