【发布时间】:2015-07-22 21:08:05
【问题描述】:
我的 Xamarin PCL 中有一个类,它调用 System.Reflection.GetRuntimeProperties。例如,假设我的 PCL 类有这个方法:
public string ExampleMethod(string arg) {
if(arg == null) return null;
IEnumerable<PropertyInfo> infos = this.GetType().GetRuntimeProperties();
return infos[0].Name;
}
然后我有一个 Xamarin.UITest 项目,它引用 PCL 项目并测试这个类。到目前为止,我的 TestFixture 中有两个测试用例,在我们的示例中如下所示:
[Test]
public void TestExampleMethod_ArgNull_Null(){
Assert.That (exampleInstance.ExampleMethod(null), Is.Null);
}
[Test]
public void TestExampleMethod_ArgNotNull_NotNull(){
Assert.That (exampleInstance.ExampleMethod("testValue"), Is.NotNull);
}
当我运行 Xamarin.UITest 项目时,它会编译、运行测试并在 Android 和 iOS 平台上正常完成。 TestExampleMethod_ArgNull_Null 测试通过,因为它提前返回。但是,TestExampleMethod_ArgNotNull_NotNull 测试失败:
System.MissingMethodException:找不到方法“RuntimeReflectionExtensions.GetRuntimeProperties”。
所以看起来即使一切都编译得很好,并且我能够很好地运行其他测试用例,但 Xamarin.UITest 项目无法使用 System.Reflection 中的任何内容。有谁知道我如何调试这个?
【问题讨论】:
标签: unit-testing xamarin nunit missingmethodexception xamarin-test-cloud