简体   繁体   中英

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. You just need mark your class as [TestFixture] and mark your methods with attribute [Test] or [TestCase] or [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.

More details you can read at github NUnit website: https://github.com/nunit/docs/wiki/NUnit-Documentation ;

And by the way, it is a bad practice use static method to call all tests.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM