Visual Studio Unit Testing of Windows Forms

后端 未结 8 2090
既然无缘
既然无缘 2020-12-28 09:09

We\'re working on a project here in Visual Studio 2008. We\'re using the built-in testing suite provided with it (the Microsoft.VisualStudio.TestTools.UnitTesting namespace

8条回答
  •  借酒劲吻你
    2020-12-28 09:52

    It's quite easy to test Winforms with ApprovalTests (www.approvaltests.com or nuget approval tests) and they are compatible with MsTest as well as Nunit.

    There's a video here of how to do it: https://www.youtube.com/watch?v=hKeKBjoSfJ8

    But the process is simple. 1) create the form you want to test in the state you want it verified. 2) call WinFormApprovals.Verify(form)

    ApprovalTests uses the golden master paradigm to screen capture the result. if you like it simply rename the file to .approved and the test will pass.

    The great thing about this for refactoring existing code is you don't even have to worry about what the result is, since you are only concerned that you are not changing it.

提交回复
热议问题