标签:
[Test] public int TestNUnit4() { Assert.Greater(10, 11, "不知道具体结果"); return 1; }
运行之后,如图所示,会提示相应的测试方法运行不了,(注意是Invalid,而不是断言失败的Failed),原因是方法有一个非空的返回类型,而nunit期望的是无返回结果的方法。
3.如果想让某个方法暂时不运行测试(或者说测试的时候忽略),可以给它附加了Ignore属性。
[Test] [Ignore("the method is not ready yet")]//方法标记Ignore属性,会在nunit中忽略这个方法的运行,呈现黄色。 public void TestNUnit3() { Assert.AreEqual(10, 11, "it is not equal"); }
[TestFixture] [Ignore("the class is not ready yet")] public class Test { [Test] public void TestNUnit() { Console.WriteLine("12121"); Assert.AreEqual(1, 2, "it is not equal"); } [Test] public void TestNUnit1() { Assert.AreEqual(1, 1 ,"it is not equal"); } [Test] public void TestNUnit2() { Assert.AreEqual(1, Assert.Counter); } . . . }
[Test] public void Method1() { var a = 1; var b = 0; var test = a / b; Assert.Pass("assert pass"); }
[TestFixture] public class Test { [Test] public void TestNUnit() { Console.WriteLine("12121"); Assert.AreEqual(1, 2, "it is not equal"); } //省略其他测试方法... [SetUp] public void SetUp() { Console.WriteLine("SetUp"); } [TearDown] public void TearDown() { Console.WriteLine("TearDown"); } }
运行效果如图:
标签:
原文地址:http://www.cnblogs.com/xtechnet/p/CSharpUnitTest.html