什么是xUnit中的文本固定装置?

时间:2020-05-01 14:39:47

标签: c# unit-testing xunit

我的课本说:

测试装置是测试所针对的对象。

我有点困惑,是测试夹具是对象(类的实例),类还是方法?

假设我们有以下代码:

public class CustomerTests
{
    [Fact]
    public void Test1()
    {
       //Arrange
       Store store = CreateStoreWithInventory(Product.Shampoo, 10);
       Customer sut = new Customer();

       //Act
       bool success = sut.Purchase(store, Product.Shampoo, 5);

       //Assert
       Assert.True(success);
    }

    [Fact]
    public void Test2()
    {
       //Arrange
       Store store = CreateStoreWithInventory(Product.Shampoo, 10);
       ...      
    }

    ...//more tests use CreateStoreWithInventory

    private Store CreateStoreWithInventory(Product product, int quantity)
    {
       Store store = new Store();
       store.AddInventory(product, quantity);
       return store;
    }
}

在我的示例中,

文本固定是CreateStoreWithInventory方法吗?如果是,则文本夹具不是对象,那么为什么不将文本夹具的定义更改为“可以被其他测试重用的方法”呢?

0 个答案:

没有答案