简体   繁体   English

将测试名称作为参数传递

[英]Passing the test name as a parameter

I am using Junit5 parametrizedTests and want to know if there is a possibility to generate the test name with a more advance way than to use something more advanced than @DisplayName.我正在使用 Junit5 parametrizedTests 并想知道是否有可能以比使用比 @DisplayName 更高级的方式更高级的方式生成测试名称。

The best thing for me would be having a way to use a method to generate the test name using a specific logic and the parameters that are passed to that test.对我来说最好的办法是使用一种方法来使用特定逻辑和传递给该测试的参数来生成测试名称。

Thanks in advance.提前致谢。

You could extends DisplayNameGenerator.ReplaceUnderscores and use it in annotation @DisplayNameGenerator:您可以扩展DisplayNameGenerator.ReplaceUnderscores并在注释 @DisplayNameGenerator 中使用它:

@DisplayNameGeneration(YorNameGenerator.class)
class YourTest {
    ...
}

Have a look at example in the documentation查看文档中的示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM