JUnit 5中的TestName规则等效于什么? [英] What is the equivalent of TestName rule in JUnit 5?

查看:296
本文介绍了JUnit 5中的TestName规则等效于什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在JUnit 5中获得测试方法的名称?

How can I get name of the test method in JUnit 5?

推荐答案

在测试方法中声明类型为TestInfo的参数,JUnit会自动为该方法提供该实例的一个实例:

Declare a parameter of type TestInfo in your test method and JUnit will automatically supply an instance of that for the method:

@Test
void getTestInfo(TestInfo testInfo) { // Automatically injected
    System.out.println(testInfo.getDisplayName());
    System.out.println(testInfo.getTestMethod());
    System.out.println(testInfo.getTestClass());
    System.out.println(testInfo.getTags());
}

您可以从TestInfo实例中获得测试方法名称(以及更多),如上所示.

You can get test method name (and more) from the TestInfo instance as shown above.

这篇关于JUnit 5中的TestName规则等效于什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆