Goal : testing TDD in a typical enterprise Java environment.
Context :
Frameworks used (even if it’s overkill, I practice project based learning) :
- DAO : Hibernate
- Spring IoC
- Front : Spring MVC + Twitter Boostrap (if possible)
- TDD : JUnit
- DB : PostgreSQL
My project is a simple billing system which would help freelancers create, edit and print/send bills to customers.
Once my project is created and configured, I don’t know where to start.
Let’s say my first my first feature is to create a bill with a unique number and a title.
Question : What should I test first ?
- the Domain layer with a createBill(String title) method which would generate a unique Serial Number ? I’d mock the DB layer.
- the UI first, mocking the service layer ? I don’t know how to do it.
Thanks in advance for your answers,
Cheers
Start with a test 🙂
What does your system do?
First test complete!
Make it pass, move on to the next test…
I’ve obviously skipped the refactoring steps here, but now that you have the tests, and the code that goes with it, you need to evaluate it for more opportunity. I’m imagining the code looking something like this.
Looking at this code, it seems ok, but may violate the Single Responsibility Principle (SRP). Here the
BillingSystemgenerating a bill as well as managing the invoice number. This is an opportunity for refactoring. After the refactoring, your design may look something like this:Your design is better and your tests all pass. Next thing to do is refactor out the tests to remove the implementation details from them. They may end up looking something like:
As a part of this refactoring, you would likely create some tests around your
InvoiceNumberingclass.Hope that’s enough of a start. Left a lot out. 🙂
Hope that helps!
Brandon