Reputation: 2762
I have read/watched so much about TDD & BDD recently that I really want to master it. I have been a developer that only writes code and then tests it from outside (like we always started). The problem seems to be in getting up and running with TDD. I want to just create a simple Winform app in which I want to show a list of something lets say products. I just don't know where to get started, should I write a test for controller first? the controller needs reference to view and service and so on so forth. ASP.Net MVC is built for testing therefore it is a bit easy to get started but Winforms are a real pain. Kindly give me some Videos (Most preffered) that show TDD in Winforms.
I have watched tons of videos that show you testing a class or feature but how do you test UI that does not support testing?
In short I want to know if anyone has been doing TDD for a while, how does he/she do it in Winforms?
I have written loads of code that I just delete because I get stuck, Please help!
Upvotes: 4
Views: 2394
Reputation: 2268
The controller is a good starting point. Extract the View public api to an interface an test the interaction of the controller with that interface using a Mocking Framework. You can do the same for the service layer too. Also, I would take the bottom-up approach for this application and unit test the lower level layers before adding tests to the UI layer. On the UI layer I will write a set of Acceptance Tests using a BDD framework and use mocking frameworks to make those tests lightweight and to reduce the number of tests.
Good luck!
Upvotes: 0
Reputation: 4399
I'm new to TDD too, and just like you I'm trying to learn. Here's what I've come up with during my searches, maybe it will help you too:
Good luck with your search.
Upvotes: 3
Reputation: 17677
Here's how I do it for any kind of UI, be it Web or Winforms or WPF or Swing in Java or even a web service interface that's going to be used by another system.
Your controller now has no behavior; just static data - but it's got the right API for the UI, and now you know how the UI wants to use it.
Those are your unit tests! If you know that your controller is going to need some other classes to collaborate with, you can mock those out too.
Once your collaborators are mocked out, you already know how the controller wants to use them. Again, you have the API for those collaborators already, because the controller is using them.
This is what we're doing when we talk about "outside-in" in BDD.
Upvotes: 4