2
用於參數化單元測試在groovy
我已經準備的數據:Groovy數組。 。在它們之間[[],[]]差指定者()和[[],[]] *指定者()
@Parameterized.Parameters
static List data() {
[
['20101113', 'DATE',
'20101114', 'DATE',
'some statement',
'20101101T000000/20110101T000000',
null,
['some', 'expected', 'data', 'results']]
// ...and other
]*.toArray()
}
它能夠正常工作。我檢查了這個代碼,試圖用].toArray()
簡化替換]*.toArray()
。
java.lang.Exception: FirstParametrizedTest.data() must return a Collection of arrays.
at org.junit.runners.Parameterized$TestClassRunnerForParameters.computeParams(Parameterized.java:94)
at org.junit.runners.Parameterized$TestClassRunnerForParameters.createTest(Parameterized.java:86)
at org.junit.runners.BlockJUnit4ClassRunner$1.runReflectiveCall(BlockJUnit4ClassRunner.java:236)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.BlockJUnit4ClassRunner.methodBlock(BlockJUnit4ClassRunner.java:233)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.junit.runners.Suite.runChild(Suite.java:128)
at org.junit.runners.Suite.runChild(Suite.java:24)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:51)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:237)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
我恢復了我的變化回來了,它的工作原理,但我不明白爲什麼指令].toArray()
是意外? ].toArray()
如何工作以及].toArray()
和]*.toArray()
之間的區別是什麼?
'* .'是一個傳播點運算符。希望這個例子會有所幫助 - http://mrhaki.blogspot.in/2009/08/groovy-goodness-spread-dot-operator.html – Rao