有没有办法将 NUnit 测试指定为 "extra credit"?

Is there a way to specify an NUnit test as "extra credit"?

我对 API 进行了一些测试,我希望能够表达某些反映 "aspirational" 或 "extra credit" 要求的测试 - 换句话说,这很棒如果他们通过了,但如果他们没有通过也没关系。例如:

[Test]
public void RequiredTest()
{
    // our client is using positive numbers in DoThing();
    int result = DoThing(1);
    Assert.That( /* result is correct */ );
}

[Test]
public void OptionalTest()
{
    // we do want to handle negative numbers, but our client is not yet using them
    int result = DoThing(-1);
    Assert.That( /* result is correct */ );
}

我知道 Ignore 属性,但我希望能够标记 OptionalTest 使其仍然在 CI 服务器上运行,但没问题如果它没有通过 - 一旦通过,我想引起注意并可能将其作为一项要求。有没有支持这个的主要单元测试框架?

我会使用警告来实现这一点。这样-您的测试将打印 'warning' 输出,但不会失败,也不会使您的 CI 构建失败。

参见:https://github.com/nunit/docs/wiki/Warnings

as soon as it does, I would like to take notice and perhaps make it a requirement.

这部分是一个稍微独立的要求!很大程度上取决于你想要 'take notice' 的方式!考虑查看自定义属性 - 可以编写一个 IWrapSetUpTearDown 属性,它会在相关测试通过时发送电子邮件。在此处查看文档:https://github.com/nunit/docs/wiki/ICommandWrapper-Interface

后者是一个更不寻常的要求 - 我希望必须做一些定制来满足您的需求!