Testing framework for C# WPF application

Viewed 3380

I have already created C# WPF application and I would like to create test application for same. I have searched for that on Internet, I have found below test framework :

  • Nunit

  • Robot framework

  • Unit testing

I am confused to select the best test framework for C# WPF application. Can you please suggest me

3 Answers
  1. Use an accepted pattern such as MVVM to ensure that there’s no business logic in the UI.

  2. Use NUnit or similar to test the business logic.

  3. Don’t bother with automatically testing the view. It should be simple enough so if it looks right, it is right.

I assume your question is about unit test frameworks.

NUnit is well tested and proven to work. I don't know about the other two but there's also Microsoft's one and xUnit. You really should check xUnit out: https://xunit.github.io/docs/why-did-we-build-xunit-1.0.html

It's actually just a matter of preference. Go after the one you feel comfortable with. Test the others and decide. I can recommend you xUnit as I work with it myself. There's no the best.

You don't really need a third-party framework for writing unit test if you don't want to. You could just create a Unit Test Project (Templates->Visual C#->Test->Unit Test Project) using the built-in Visual Studio template.

You would then add a reference to the project where your view model classes are implemented and write unit tests against these:

[TestMethod]
public void SomeTest()
{
    var vm = new YourViewModel();
    vm.PropertyA = "a";
    Assert.IsNotNull(vm.PropertyA);
}

Of course this assumes that you have implemented your application with testability in mind. MVVM is the recommended pattern to use when developing XAML based UI applications. If you haven't learned it yet, you should. MSDN provides a good starting point: https://msdn.microsoft.com/en-us/library/hh848246.aspx.

Related