How to apply TDD over enterprise application that has layered architecture?
I want to know how to apply TDD to an application that has following
- WPF application (6-7 screens)
- 3-4 Modules (Prism modules)
- Some application services (Logging, Exception Handling, Security, Authorization, Core Business services library)
- Data Access Layer (using Entity Framework)
- A bunch of WCF services
As I understand, first thing is to get the architecture right. As a result, Components are identified.
Next is to develop the components independently, where I stuck.
With TDD, design (of a component) evolves with time. For a component following is the way (I perceive) to go with TDD
- Identify all use cases
- Identify all test cases
- For each test case, write all scenario, and for each scenario, write a failing test case. Make little code, so that test case is passed. Add to list, if new scenario is found
- Follow Red-Green-Refactor until all the test cases (corresponding to all scenario) are passed
- In the refactoring, dont forget DRY, YAGNI, Mocking, DI, etc,etc.
- End result is well designed Component (how much well designed depends on experience and skills of developer).
Problem i face is, For a component, until i reach to Step 6 of TDD process, i donot know the interfaces. Since there are multiple components, multiple teams, No body is sure what they will come up with.
Now the summary Questions based on above scenario
- Is there some basics that I am missing? Please point me to appropriate resources if yes.
- How to apply TDD over layered architecture?
- How to do parallel development of multiple components
- Best practices for TDD with WPF UI (PRISM)
- Best practices for TDD with Database (using Entity Framework)
- How to decide WCF service contract, when using TDD?
I think you have the order wrong. You’re choosing the architecture, then trying to get there with TDD. The idea behind TDD is to start w/ nothing, and arrive at an layered architecture if it’s needed.
Of course, that probably doesn’t help when you’re looking at a very large project, because there has to be some organization to it all. My usual approach is to try to divide the work into something that makes sense to real people (not programmers). And no, I’m not really talking full Domain Driven Design. I’m referring to just thinking of the different pieces as an outsider would.
For example, if I want to make a program that represents a cash register (something that can hold money and figure totals).
What’s the first thing I want it to do? Hold and dispense money. So, I need a drawer (first component, give it to a team). I need a button to open it (second component, second team), etc… The key is to focus on what it should do, not how it should do it.
Yes, there’s a lot of contract/protocol talks that have to happen. Those are things the teams involved will have to work out as they hit the problem. The key is to focus on what you want it to do. Solve the now problem. Don’t pre-optimize. You’ll probably find that not all of the components require all of the layers.
The short answer to the best practices questions is “it depends.” (The cheesy, common, and overused IT answer.) The general rules are you want to focus on behavior, not implementation. Ensure you can trust the tests (they produces the correct results all the time). Make sure you test as much as is possible… Or, numbered…
Sorry if this was really vague. Google the names I dropped, they’re good places to start. If you want a leg up on TDD, hire a couple experienced coders and use pair programming. If you can’t afford that, hire someone to come in and do some training, then do pair programming. Can’t do that? Get some books and use pair programming.
Then, beat the pairs to ensure they’re writing tests first.
At the end of the day, it’s about deciding what you want something to do, then letting the tests evolve the architecture. Not the other way around.