你不想't really need a third-party framework for writing unit test if you don' . 您可以使用内置的Visual Studio模板创建 Unit Test Project (模板 - > Visual C# - >测试 - >单元测试项目) .
然后,您将添加对实现视图模型类的项目的引用,并针对这些引用单元测试:
[TestMethod]
public void SomeTest()
{
var vm = new YourViewModel();
vm.PropertyA = "a";
Assert.IsNotNull(vm.PropertyA);
}
3 回答
我假设您的问题是关于单元测试框架 .
NUnit经过充分测试并证明可行 . 我不是't know about the other two but there'也是微软的一个和xUnit . 你真的应该检查xUnit:https://xunit.github.io/docs/why-did-we-build-xunit-1.0.html
这实际上只是一个偏好问题 . 追求你感觉舒服的那个 . 测试其他人并决定 . 我可以推荐你xUnit,因为我自己一起工作 . 没有最好的 .
使用可接受的模式(如MVVM)确保UI中没有业务逻辑 .
使用NUnit或类似方法测试业务逻辑 .
不要费心自动测试视图 . 它应该很简单,如果看起来正确,那就是对的 .
你不想't really need a third-party framework for writing unit test if you don' . 您可以使用内置的Visual Studio模板创建
Unit Test Project
(模板 - > Visual C# - >测试 - >单元测试项目) .然后,您将添加对实现视图模型类的项目的引用,并针对这些引用单元测试:
当然,这假设您已经实现了具有可测试性的应用程序 . MVVM是在开发基于XAML的UI应用程序时使用的推荐模式 . 如果你还没有学到它,你应该 . MSDN提供了一个很好的起点:https://msdn.microsoft.com/en-us/library/hh848246.aspx .