【问题标题】:Gallio unit test startup codeGallio 单元测试启动代码
【发布时间】:2012-12-18 01:05:12
【问题描述】:

这将是一个业余水平的问题。有没有办法将启动代码添加到使用 MBUnit 3.4.0.0 的测试项目中?我尝试将 [TestFixture] 和 [FixtureSetUp] 属性添加到我想首先运行的代码中,但不幸的是没有帮助。

【问题讨论】:

    标签: unit-testing mbunit


    【解决方案1】:

    在对 [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
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2011-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-23
      • 2013-04-16
      • 2012-09-02
      相关资源
      最近更新 更多