This is the source code for the tutorial about writing unit-tests using mocks.
Part 1 of the unit-testing tutorial is here.
The tutorial is not ready yet; but you can read some articles about unit-testing here:
http://smartpuffin.com/tag/unit-testing/
- Open the tutorial.
- Open
UserAgeCalculator.java
. Review the code. - Open
UserAgeCalculatorTest1.java
. What problems do you see with this test? - Open
UserAgeCalculatorTest2.java
and see how we solved one of the problems. - Open
UserAgeCalculatorTest3.java
and see how we got rid of some copy-paste that we introduced inUserAgeCalculatorTest2.java
. - Tests in
UserAgeCalculatorTest3.java
are still failing. Why? Can you think of a way to fix them?
I run this with Intellij IDEA and Java 1.8+.
- Download the source code.
- Open the folder with the code in Intellij IDEA.
- Open the file
UserAgeCalculatorTest1.java
. You'll see green "Run test" buttons next to line numbers. Press the one next toclass UserAgeCalculatorTest1
and watch the test suite execute.