代码之家  ›  专栏  ›  技术社区  ›  Niraj Sonawane

JUnit 5:如何为参数化测试提供名称

  •  0
  • Niraj Sonawane  · 技术社区  · 6 年前

    我有如下简单的参数化测试用例

    @ParameterizedTest
        @ValueSource(strings = { "Hello", "World","Test" })
        void withFixValues(String word) {
            System.out.println(word);
            assertNotNull(word);
    
        } 
    

    但在测试失败的情况下,不容易检查哪个参数值测试失败。我们是否可以根据参数来命名参数化测试用例?

    1 回复  |  直到 6 年前
        1
  •  0
  •   Niraj Sonawane    6 年前

    我们可以使用名称属性提供名称。

            @ParameterizedTest(name = "withSomeName #{index} with Value [{arguments}]")
            @ValueSource(strings = { "Hello", "World","Test" })
            void withFixValues(String word) {
                System.out.println(word);
                assertNotNull(word);
    
            }