Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 单元测试问题_C#_Unit Testing - Fatal编程技术网

C# 单元测试问题

C# 单元测试问题,c#,unit-testing,C#,Unit Testing,是否有人使用xunit,确定以下代码(实际上是想法)是否可行: public class RepositoryTester { private IRepository repository; public RepositoryTester(IRepository repository) { this.repository = repository; ) [Fact] // Analogue of [Test] in other test packages

是否有人使用
xunit
,确定以下代码(实际上是想法)是否可行:

public class RepositoryTester {

   private IRepository repository;

   public RepositoryTester(IRepository repository) {
      this.repository = repository;
   )

   [Fact] // Analogue of [Test] in other test packages.
   void CanDoWhatever() {
      // Test code
   }
}
现在,如果我尝试运行所有单元测试,那么只要
xunit
通过调用
new RepositoryTester()
尝试创建对象
RepositoryTester
(它调用构造函数而不带参数),它就会失败

我想做的事情可以等效地表示为:

var tester1 = new RepositoryTester(new SQLRepository(...));
var tester2 = new RepositoryTester(new InMemoryRepository(...));

tester1. RUN_ALL_TESTS();
tester2. RUN_ALL_TESTS();

有人知道以下行为是否可能吗?(我真的希望通过接口为每个可测试存储库使用相同的测试包)


谢谢

您可以将
RepositoryTester
抽象化,并为每种类型的存储库创建一个派生类,在无参数构造函数中创建一个适当的IRepository。继承的测试方法将针对每个具体的子类运行