Bootstrap for TDD bank kata (or any kata, really)
Kata: a Japanese word, meaning literally: "form" (型 or 形): “a detailed choreographed pattern of movements made to be practiced alone, but are also practiced within groups and in unison when training.”
- Deposit into the Account
- Withdraw from the Account
- Print the account statement
Statement should have following format:
> DATE | AMOUNT | BALANCE
> 10/04/2019 | 100.00 | 900.00
> 09/04/2019 | -200.00 | 800.00
> 01/01/2019 | 1000.00 | 1000.00
- Start with class with follwing structure:
Public class Account {
public void deposit(int amount) {}
public void withdraw(int amount) {}
public void printStatement() {}
}
-
You are not allowed to add/change any other public methods or public fields to the class – apart from a constructor
-
Use strings and integers for dates and amounts (keep it simple)
-
Don’t worry about spacing in the printed statements
-
You are not allowed to write a single line of implementation code unless there’s a test for it
-
If you think of an edge case, make a test, then go back and refactor till it works.
-
Think -> Test -> Implement
-
Red -> Green -> Refactor -> GOTO Red
-
Wrap IO calls with your own Console that you can stub and verify against
-
Your Account will probably need a Ledger, containing all the Transactions
-
Use your testing library of choice; Mockito and Assert4J is probably the java weapon of choice for this.
-
If you feel really confident, start by writing an acceptance test against the Account