我有这个方法
@TestFactory
Stream<DynamicTest> dynamicTestsFromStream() throws IOException {
initialize();
return Stream.of(core).map(
str -> DynamicTest.dynamicTest("test" + str.toString(), () -> { Just for Testing > Assert.assertTrue(false); }));
}
我的core
数组包含元素类型Tuple4
。Tuple4(String a, String b, String c, String d)
.
当我尝试寻址名称(我想要String c
)时,出现错误,在当前示例中,我的结果str
是:Tuple4@4d50efb8, Tuple4@7e2d773b, Tuple4@2173f6d9
有人能告诉我如何为 str 找到正确的索引吗?因为get(int)
无法工作,因为我无法获得当前位置?
编辑
当我把Stream.of("A","B","C").map(...);
测试赋予正确的名称“测试 A”...
那么我怎样才能给stream.of()
一个 Array(Object) 来命名测试呢?
随着Stream.of(SomeType[])
运行得到一个仅包含一个元素,即阵列流的风险。使用Arrays::stream
来代替。
假设core
是类型Tuple4[]
(如果不是,请在问题中包括实际类型),您可以执行以下操作:
@TestFactory
Stream<DynamicTest> dynamicTestsFromStream() throws IOException {
initialize();
return Arrays.stream(core) // Stream<Tuple4>
.map(tuple -> DynamicTest.dynamicTest(
"test " + tuple.c,
() -> { Assert.assertTrue(false); }
));
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句