本文介绍了在Eclipse Testrunner中具有名称的ParameterizedTest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您使用Eclipse TestRunner运行JUnit 4 ParameterizedTest时,图形表示相当愚蠢:对于每个测试,您都有一个名为 [0] [1]
可以给出测试 [0] 1] 等明确的名字?实施 toString 方法似乎没有帮助。

When you run a JUnit 4 ParameterizedTest with the Eclipse TestRunner, the graphical representation is rather dumb: for each test you have a node called [0], [1], etc.Is it possible give the tests [0], [1], etc. explicit names? Implementing a toString method for the tests does not seem to help.

(这是一个后续问题。)

(This is a follow-up question to JUnit test with dynamic number of tests.)

推荐答案

JUnit4现在,以便您可以从索引和参数的toString方法中指定一个命名模式。例如:

JUnit4 now allows specifying a name attribute to the Parameterized annotation, such that you can specify a naming pattern from the index and toString methods of the arguments. E.g.:

@Parameters(name = "{index}: fib({0})={1}")
public static Iterable<Object[]> data() {
    return Arrays.asList(new Object[][] { { 0, 0 }, { 1, 1 }, { 2, 1 },
            { 3, 2 }, { 4, 3 }, { 5, 5 }, { 6, 8 } });
}

这篇关于在Eclipse Testrunner中具有名称的ParameterizedTest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 14:33