我有个单元测试:
[Test]
[AutoMoqData]
[TestCaseSource(typeof(PhoneNumberTestCases))]
public void PopulatesPhoneProperty(
string inputValue,
string expectedValue)
Entity source,
[NoDefaultEnum] ConcreteUserMapper sut,
{
source.LogicalName = "user";
source.Attributes.Add("phone", inputValue);
sut.Map(source).Phone.Should().Be(expectedValue);
}问题是,我希望我的最后两个测试方法参数(sut和source)不显式地自动实例化。现在它不起作用(没有提供足够的参数,至少提供4个参数)。有人能解决这个问题吗?我找了一天,找不到任何能帮助我的东西。
internal class PhoneNumberTestCases : IEnumerable
{
public IEnumerator GetEnumerator()
{
yield return new object[] { "800) 814-1103 ext. 3120 ext.", "80081411033120" };
yield return new object[] { "80081411033120", "80081411033120" };
yield return new object[] { "1a2b3cc4dd800", "1234800" };
yield return new object[] { "555.555.5555", "5555555555" };
yield return new object[] { "555-555-5555", "5555555555" };
yield return new object[] { "555.555.5555", "5555555555" };
yield return new object[] { "555?555!5555", "5555555555" };
yield return new object[] { "555-555-5555 x6666", "55555555556666" };
yield return new object[] { string.Empty, string.Empty };
yield return new object[] { null, null };
}
}}
发布于 2020-02-16 17:59:53
我在nunit上有点生疏,但我认为test source属性需要为正在修饰的方法指定的所有方法参数。
最简单的选择是从测试中删除automoq属性,并更改测试用例类,以实例化要传递给该测试的模拟对象。
https://softwareengineering.stackexchange.com/questions/405191
复制相似问题