C# - WPF : testing strategies

前端 未结 5 1996
情书的邮戳
情书的邮戳 2021-02-03 12:22

I\'m new to C# 4.0 and WPF and I\'m about to start a new application.

Coming from a C++/MFC world, I\'m interested in testing strategies used with the up to date technol

5条回答
  •  长情又很酷
    2021-02-03 12:47

    I care a lot about the view looking right. That means unit testing. For me, the best technique is to ONLY test the view in a single unit test, that means

    model + view = result.

    The open source verification utility ApprovalTests (www.approvaltests.com or nuget ) will easily test Wpf views.

    You can see it in action here: http://www.youtube.com/watch?v=Xc_ty03lZ9U

    I'd recommend watching the winforms video 1st though, as it goes into more of the theory of how to test views in general: http://www.youtube.com/watch?v=hKeKBjoSfJ8

    The code itself will look like

    var model = CreateModel();
    var yourWpfView = new YourWpfView(model);
    WpfApprovals.Verify(yourWpfView);
    

    and it will take a screenshot and compare it against a golden master.

提交回复
热议问题