Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test BusyIndicator IsBusy property using TDD

Tags:

tdd

mvvm

wpf

I am reading Professional Test Driven Development with C# and it has opened up my eyes to some cool approaches and frameworks. I really like the flow of red-green-refactor and I knocked out a ton of library code in the past couple of weeks.

For the WPF front end, I wanted to try the same sort of approach with the ViewModel. Everything was going fine until I started thinking about how to add the bool that the View's BusyIndicator IsBusy property will bind to. More specifically, what tests should I write so that I can make sure long methods will set IsBusy properly. I know I could probably do this easily without doing the pure TDD approach, but was curious how others approach simple tasks like this.

like image 571
dukesta3 Avatar asked Nov 30 '25 12:11

dukesta3


1 Answers

If I understand your question correctly, you should be able to create a mock instance of your View. Then in your test(s), once you have the test conditions arranged & have acted upon them (the first & second A's in "Arrange/Act/Assert"; see: http://www.telerik.com/help/justmock/basic-usage-arrange-act-assert.html), you can verify whether the IsBusy property evaluates to true.

Also, you may find it useful to also have some type of conditional check added to the property, so as to behave slightly differently while testing. Here's a nice example of how to accomplish this:

  • How-to: Determine if code is running as part of a unit test
  • Answer that illustrates similar, relevant usage: https://stackoverflow.com/a/3598990/1796930
like image 161
Alexander Avatar answered Dec 03 '25 11:12

Alexander



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!