我正在尝试使用nUnit为Xamarin Forms项目编写单元测试。但是当我在await vm.LoadExes();
中调用方法Viewmodel
时,我收到了错误:
类型' BindableBase'在未引用的程序集中定义。您必须添加对程序集的引用' Prism,Version = 6.2.0.0,Culture = neutral,PublicKeyToken = 91a96d2a154366d8'。"
public class ExesTests
{
private Mock<IExService> mockExService;
private Mock<INavigationService> mockNavigationService;
private Mock<IPageDialogService> mockPageDialogService;
[TestInitialize]
public void Setup()
{
mockExService = new Mock<IExService>();
var exes = new List<Ex>()
{
new Ex()
};
mockExService.Setup(o => o.GetExes().Result).Returns(exes);
}
[TestMethod]
public async Task GetExesTest()
{
var vm = new ExesPageViewModel(mockExService.Object,
mockNavigationService.Object, mockPageDialogService.Object);
await vm.LoadExes(); // Getting error here
//Assert here
}
}
Prism用于MVVM的Xamarin Forms项目
ViewModel
中方法的签名是
internal async Task LoadExes()
{
//Do something
}
方法标记为internal
,以便可以从单元测试项目访问。