[英]Does a nunit test case need static main method?
[TestFixture]
public class CalciTest
{
public static void main(string[] args)
{
calci calculator = new calci();
add_Test();
sub_Test();
}
[Test]
public void add_Test()
{
int sum = calculator.add(5, 6);
Assert.AreEqual(sum, 11);
}
[Test]
public void sub_Test()
{
int diff = calculator.sub(15, 6);
Assert.AreEqual(diff, 9);
}
}
According to NUnit framework documentation, you don't need a static main method.根据 NUnit 框架文档,您不需要静态 main 方法。 You just need mark your class as [TestFixture] and mark your methods with attribute [Test] or [TestCase] or [TestCaseSource].
您只需要将您的类标记为 [TestFixture] 并使用属性 [Test] 或 [TestCase] 或 [TestCaseSource] 标记您的方法。
After building your project you should be able to see your test in test explorer.构建项目后,您应该能够在测试资源管理器中看到您的测试。
If you use a Visual Studio as IDE you could find it in Test -> Window -> Test Explorer.如果您使用 Visual Studio 作为 IDE,您可以在测试 -> 窗口 -> 测试资源管理器中找到它。
More details you can read at github NUnit website: https://github.com/nunit/docs/wiki/NUnit-Documentation ;您可以在 github NUnit 网站上阅读更多详细信息: https : //github.com/nunit/docs/wiki/NUnit-Documentation ;
And by the way, it is a bad practice use static method to call all tests.顺便说一句,使用静态方法调用所有测试是一种不好的做法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.