Kotlin - @AliasFor 不覆盖 @DisplayName 的属性

问题描述 投票:0回答:1

我正在尝试使用一些元注释为测试创建注释。我想传递一个

name
参数并通过使用
@DisplayName
将其用作
@AliasFor
的值。代码如下所示:

@Target(AnnotationTarget.CLASS)
@Retention(AnnotationRetention.RUNTIME)
@Nested
@DisplayName("")
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
internal annotation class EndpointTest(
    @get:AliasFor(annotation = DisplayName::class, attribute = "value")
    val name: String
)

@DisplayName
的值没有被覆盖,这是意外的。似乎完全被忽略了。我在这里使用
""
因为 value 没有默认值

spring spring-boot kotlin junit annotations
1个回答
0
投票

@AliasFor
是一个Spring注解,需要使用Spring的注解搜索工具来支持它。

@DisplayName
是一个 JUnit Jupiter 注释,只能通过 JUnit 5 的注释支持实用程序进行查找(不包括对 Spring 的
@AliasFor
注释的支持)。

因此,JUnit 永远不会将

name
注释中的
@EndpointTest
属性解释为
value
@DisplayName

© www.soinside.com 2019 - 2024. All rights reserved.