【发布时间】:2012-12-18 01:05:12
【问题描述】:
这将是一个业余水平的问题。有没有办法将启动代码添加到使用 MBUnit 3.4.0.0 的测试项目中?我尝试将 [TestFixture] 和 [FixtureSetUp] 属性添加到我想首先运行的代码中,但不幸的是没有帮助。
【问题讨论】:
标签: unit-testing mbunit
这将是一个业余水平的问题。有没有办法将启动代码添加到使用 MBUnit 3.4.0.0 的测试项目中?我尝试将 [TestFixture] 和 [FixtureSetUp] 属性添加到我想首先运行的代码中,但不幸的是没有帮助。
【问题讨论】:
标签: unit-testing mbunit
在对 [TestFixture] 中包含的测试进行任何测试之前,应该执行一次 [FixtureSetUp],但两者不能互换使用。
这是一个简单的例子。诚然,该类不必使用 [TestFixture] 属性进行修饰,但这是一种很好的做法。
[TestFixture]
public class SimpelTest
{
private string value = "1";
[FixtureSetUp]
public void FixtureSetUp()
{
// Will run once before any test case is executed.
value = "2";
}
[SetUp]
public void SetUp()
{
// Will run before each test
}
[Test]
public void Test()
{
// Test code here
Assert.AreEqual("2", value);
}
[TearDown]
public void TearDown()
{
// Will run after the execution of each test
}
[FixtureTearDown]
public void FixtureTearDown()
{
// Will run once after every test has been executed
}
}
【讨论】: