NUnit TestFixtureSetup 和 TestFixtureTearDown
TestFixtureSetup 和 TestFixtureTearDown
在所有测试开始前(TestFixtureSetup)或结束后(TestFixtureTearDown)运行一 次。记住他只运行一次,而不论有多少个Test函数。因此一个TestFixture只能有一个TestFixtureSetup或TestFixtureTearDown。
示例: 测试用例
[TestFixture] public class TestFixtureSetUpAndTearDownTest { [TestFixtureSetUp] public void RunBeforeAllTests() { Console.WriteLine( "TestFixtureSetUp" ); } [TestFixtureTearDown] public void RunAfterAllTests() { Console.WriteLine( "TestFixtureTearDown" ); } [SetUp] public void RunBeforeEachTest() { Console.WriteLine( "SetUp" ); } [TearDown] public void RunAfterEachTest() { Console.WriteLine( "TearDown" ); } [Test] public void Test1() { Console.WriteLine( "Test1" ); } 被测试类 [Test] public void Test2() { Console.WriteLine( "Test2" ); } } 运行结果: TestFixtureSetUp SetUp Test2 TearDown TestFixtureTearDown
转载请注明文章来自:程序猴(http://www.chengxuhou.com/)
posted on 2013-12-27 13:46 程序猴chengxuhou.com 阅读(742) 评论(0) 编辑 收藏 举报