单元测试重载方法 C#

问题描述 投票:0回答:1

我想在两个重载方法上编写一个通用单元测试用例,我将断言相同的条件。我想避免为每个重载编写单元测试。最好的方法是什么?

   public void method1(Type1 t) {
      \\ Do something on t
       privateMethod()
   }

   public void method2(Type2 t) {
      \\ Do something on t
       privateMethod()
   }

   private void privateMethod()
       ...execute common operations
   }
}
c# unit-testing xunit
1个回答
0
投票

你可以这样做

[Theory]
[InlineData(/* Input parameters for method1 */)]
[InlineData(/* Input parameters for method2 */)]
public void method(Data1 x)
{
  // Call the method (method1 or method2)
}
© www.soinside.com 2019 - 2024. All rights reserved.