java - 相当于 C# 中的 Java 元注释

标签 java c# xunit

我想简化一些Xunit属性,以减少一些代码并将所有测试实现为构造型。例如,我在集成测试代码中使用其 TraitAttribute 来区分同一测试类中众多 stub 之间的测试端点。

[Fact]
[Trait("Action", "Create")]
public async Task CreateCategory_ReturnsNewCategoryIfParamsValid()
{
  // test case implementation       
}

大多数情况中,Java 中的 Spring Framework 允许我将注释重写为 meta-annotations .

是否可以在C#中对属性执行相同的操作?

最后,我想编写如下测试 stub 。

[Fact]
[ActionTrait(Actions.Create)]
public async Task CreateCategory_ReturnsNewCategoryIfParamsValid()
{
  // test case implementation       
}

最佳答案

Is it possible to do the same thing in C# for attributes?

是的,由于 C# 属性只是从 Attribute 派生的类,并且类可以具有属性,这意味着属性本身也可以具有属性。

这完全取决于读取和处理属性以查找属性上的属性的代码。

关于java - 相当于 C# 中的 Java 元注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60480638/

相关文章:

java - Camel .to 文件扩展名

java - 为什么我无法在 Spring-5.0.0.RELEASE 中导入 ApplicationContext

c# - LINQ where 子句中的三元运算符

c# - ASP.Net MVC 图像上传通过缩小或填充调整大小

c# - 如果您无法控制类,如何模拟类中的方法?

java - 可以使用隐藏参数的 RedirectRequestTarget 吗?

java - 在linux上编译java源代码

c# - 在内存中创建文件夹?

c# - 如何识别我的代码何时在 C# 中进行测试?

c# - XUnit 测试 - InMemory 与真实数据库