Unit test WPF Bindings

后端 未结 5 580
萌比男神i
萌比男神i 2021-01-04 11:08

I am trying to unit test my WPF databindings using the test suit provided by Microsoft Team System. I would like to be able to test the bindings without showing the window

5条回答
  •  醉酒成梦
    2021-01-04 11:33

    While looking for a solution to convert WPF binding errors into exception, I figured out that it can also be used in a unit test project.

    The technique is very simple:

    1. Derive a TraceListener that throws instead of logging
    2. Add that listener to PresentationTraceSources.DataBindingSource

    Please see the complete solution on GitHub, it includes a unit test project.

    Failed test in Visual Studio

提交回复
热议问题