- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我定义了自己的 JUnit 注释:
@ParameterizedTest
@MethodSource("myorg.qa.ccrtesting.DataProviders#standardDataProvider")
@Tags({@Tag("ccr"), @Tag("standard")})
public @interface CcrStandardTest {
}
然后,我可以在测试中使用该注释:
@CcrStandardTest
public void E0010_contact_standard (String testData) {
...
-ea
myorg.qa.ccrtesting.ccrstandardtests.CcrStanConTest
- 这是 IDE 建议的(并经过验证指向正确的类,其中包含我的原型(prototype)测试方法)但是,这会导致:jupiter.api.extension.ParameterResolutionException:在方法 [public void... 中没有为参数 [java.lang.String arg0] 注册 ParameterResolver。
我尝试从测试方法签名中删除 String testData
,但 JUnit 没有执行任何测试:未找到测试
当我在原型(prototype)测试方法上方添加 @Test
时,它会执行但是:
@CcrStandardTest
下定义的注释均未应用可疑的组合 @Test 和参数化源
@ParameterizedTest
暗示 @Test
,只是不确定为什么 IDE 能够找到自定义注释,而 JUnit 却不能?)最佳答案
正如您所发现的,您需要将 @Retention(RUNTIME)
添加到您的组合注释中,以便 JUnit 能够看到它。 Java 中的注释具有三种不同的保留策略:
Annotations are to be discarded by the compiler.
Annotations are to be recorded in the class file by the compiler but need not be retained by the VM at run time. This is the default behavior. [emphasis added]
Annotations are to be recorded in the class file by the compiler and retained by the VM at run time, so they may be read reflectively.
正如我上面强调的,如果您没有显式添加 @Retention(...)
,则使用 CLASS
策略。这不适用于 JUnit,因为 JUnit 不会扫描 *.class
文件(即字节码)中的注释,它会反射性地扫描加载的类来查找测试方法。如果没有 RUNTIME
保留策略,您的注释将无法通过反射方式访问,因此 JUnit 永远不会看到它,因此不会执行测试。
@Target
注释:
Indicates the contexts in which an annotation type is applicable. The declaration contexts and type contexts in which an annotation type may be applicable are specified in JLS 9.6.4.1, and denoted in source code by enum constants of
java.lang.annotation.ElementType
.If an
@Target
meta-annotation is not present on an annotation typeT
, then an annotation of typeT
may be written as a modifier for any declaration except a type parameter declaration.If an
@Target
meta-annotation is present, the compiler will enforce the usage restrictions indicated byElementType
enum constants, in line with JLS 9.7.4.
在我对 your other question 的回答中,我使用了:
@Target({ElementType.ANNOTATION_TYPE, ElementType.METHOD})
因为这与 @ParameterizedTest
使用的目标相同。我认为将其限制为 METHOD
是一个好主意,因为 @ParameterizedTest
的设计者显然认为只有方法应该由参数化测试扩展直接扩展(请参阅 §5 Extension Model )。包含 ANNOTATION_TYPE
允许您将组合注释放在另一个注释上,从而创建另一个组合注释。
您还会看到我包含了 @Documented
:
If the annotation
@Documented
is present on the declaration of an annotation typeA
, then any@A
annotation on an element is considered part of the element's public contract. In more detail, when an annotation typeA
is annotated withDocumented
, the presence and value of annotations of typeA
are a part of the public contract of the elementsA
annotates. Conversely, if an annotation typeB
is not annotated withDocumented
, the presence and value ofB
annotations are not part of the public contract of the elementsB
annotates. Concretely, if an annotation type is annotated withDocumented
, by default a tool like javadoc will display annotations of that type in its output while annotations of annotation types withoutDocumented
will not be displayed.
请注意,这些注释 - @Retention
、@Target
和 @Documented
- 并非特定于 JUnit。这些注释对于 Java 中注释的工作方式至关重要,每个注释都位于 java.lang.annotation
包中。
关于java - JUnit5-木星 : Composed ( ="meta") annotation does not resolve to annotation definition,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60339277/
我使用以下命令使用 Composer 删除了一个包。 composer remove sjparkinson/static-review 以上命令从 composer.json 中删除条目文件但 co
我刚刚开始使用 Composer 功能,你告诉它查看本地目录的依赖关系,这样你就可以开发一个库和一些并行使用该库的东西,而不必一直推送到 git 来更新,这是惊人的。例如 "repositories"
composer 和有什么区别和 composer.phar ? 例子: composer install composer.phar install 我一直看到使用 composer.phar 编写
阅读docker-compose -h或this official manual的帮助将为我们提供--project-directory PATH选项 docker-compose [-f ...]
我已经使用他们的安装指南在我的 Linux/Apache 服务器上的根目录(这是默认选择)中成功安装了 Composer。到目前为止,一切都非常简单,除了我必须进行的一个 php.ini 调整( de
在我的 composer.json配置文件,我有: "require": { "zendframework/zend-log" : "~2.3", }, "require-dev": {
从 Composer 安装此软件包后,我想复制位于软件包内的一些文件。 实际上,我希望在从 Composer 安装或更新软件包后,将下载的软件包中可能存在的某个文件复制到另一个目录。我用 script
我对码头公司还是个新手。我使用的是最新版本的Python、Django和Docker。我已经在这个项目上工作了两周了,我已经创建了docker-compose.yml文件,并且已经构建了我的docke
我正在尝试使用 composer 安装一个 github 项目并得到以下错误 Composer [UnexpectedValueException]您的 github.com 的 Github oau
我开发 Symfony 包的工作流程如下: 安装 Symfony 为新包创建一个 git repo,在其中放置一个 composer.json 文件 需要顶级 composer.json 中的新包,使
我正在尝试使用 composer 安装 github 项目并收到以下错误 Composer [UnexpectedValueException] 您用于 github.com 的 Github oau
我们在项目中使用了 composer。当我开发和/或向项目提交任何内容时,我通常应该使用 composer install;更新依赖项只是偶尔进行。 我们还使用 https://github.com/
我在 youtube 上学会了这个抽屉 https://www.youtube.com/watch?v=JLICaBEiJS0&list=PLQkwcJG4YTCSpJ2NLhDTHhi6XBNfk9
我知道在 onClick 中调用可组合函数是不可能的。 @Composable 调用只能在 @Composable 函数的上下文中发生 撰写版本 - alpha06 但我坚持以下要求。 要求是, 在
这是我的 docker-compose.yml 文件: version: '3.1' services: a: image: tutum/hello-world b: imag
创建Asset实例时是否有auto_increment字段类型可用。例如, Assets ID 应该是自动生成的字段,应该在运行时创建,而不是在应用程序级别提及该值。我可以通过创建一个交易处理器函数来
在 Composer 项目中,我必须添加一个库,它没有 composer.json 并且不使用命名空间。因此,我调整了项目的 composer.json 以添加库: { [...] "
当 vendor 目录中已经有一些组件被下载时.. 在上面运行 install 以及运行 update 时有什么影响? 最佳答案 所以我有同样的问题,这是我发现的: composer install
尝试运行 composer install 时出现此错误。我已经运行了 composer update,我正在尝试使用这个最新的锁定文件进行安装。没有任何帮助。 Loading composer re
当我尝试做: $ sudo php composer.phar update 我收到此警告: Warning: This development build of composer is over 3
我是一名优秀的程序员,十分优秀!