NUnit 3.4.1,JustMock 2016.2.713.2
我有正在测试的课程:
public class AppManager {
public string[] GetAppSets() => Registry.LocalMachine
.OpenSubKey(@"SOFTWARE\Autodesk\AutoCAD", false)
?.GetSubKeyNames();
}
另外,我对GetAppSets
方法进行了测试:
[Test]
public void GetAppSets_Returns_ValidValue() {
const string subkey = @"SOFTWARE\Autodesk\AutoCAD";
/* The sets of applications which are based on
* AutoCAD 2009-2017. */
string[] fakeSets = new[] { "R17.2", "R18.0",
"R18.1", "R18.2", "R19.0", "R19.1", "R20.0",
"R20.1","R21.0" };
RegistryKey rk = Mock.Create<RegistryKey>();
Mock.Arrange(() => rk.GetSubKeyNames()).Returns(
fakeSets);
Mock.Arrange(() => Registry.LocalMachine.OpenSubKey
(subkey, false)).Returns(rk);
AppManager appMng = new AppManager();
string[] appSets = appMng.GetAppSets();
Assert.AreEqual(fakeSets, appSets);
}
有用。GetAppSets
但如果方法使用“ Software\Autodesk\AutoCAD ”或“ software\autodesk\autocad ”字符串而不是“ SOFTWARE\Autodesk\AutoCAD ”,我的测试将失败:appSets
变量将是null
如果字符串大小写将更改(因为该注册表密钥在我的计算机上不存在)。
因此,在这种情况下,测试人员需要知道GetAppSets
方法实现(错误的变体),或者处理不区分大小写的字符串等参数。
是否可以使用第二种变体?