如何仅在 Linux OS 上启用 运行 的 Nunit 测试(而不在 Windows 上启用 运行)?

How to enable Nunit tests to run only on Linux OS (and don't run on Windows)?

我正在使用 Nunit 来测试我的程序(当我们对程序进行构建时,测试 运行 会自动进行)。

程序 运行 在 Windows 和 Linux 操作系统上,我有一些测试应该 运行 只在 Linux Os。有什么方法可以确保这些测试 运行 仅在 Linux 而不是 Windows OS?

我知道在 JUnit 中例如可以添加标题 @EnabledOnOs(LINUX) ,但我找不到类似于 Nunit 的内容。

非常感谢。

简答:[Platform("Linux")]

NUnit 会生成一个原因,但如果您想要更详细的原因,您可以指定它。

[Platform("Linux", Reason="Only runs on Linux because... ")]

您可以在方法或整个装置上使用它 class。