Skip to content

Latest commit

 

History

History
26 lines (18 loc) · 1.15 KB

README.md

File metadata and controls

26 lines (18 loc) · 1.15 KB

ExampleUnitTestsWithMocks

This is the source code for the tutorial about writing unit-tests using mocks.

Part 1 of the unit-testing tutorial is here.

Tutorial

The tutorial is not ready yet; but you can read some articles about unit-testing here:

http://smartpuffin.com/tag/unit-testing/

What to do with this

  1. Open the tutorial.
  2. Open UserAgeCalculator.java. Review the code.
  3. Open UserAgeCalculatorTest1.java. What problems do you see with this test?
  4. Open UserAgeCalculatorTest2.java and see how we solved one of the problems.
  5. Open UserAgeCalculatorTest3.java and see how we got rid of some copy-paste that we introduced in UserAgeCalculatorTest2.java.
  6. Tests in UserAgeCalculatorTest3.java are still failing. Why? Can you think of a way to fix them?

How to run tests

I run this with Intellij IDEA and Java 1.8+.

  1. Download the source code.
  2. Open the folder with the code in Intellij IDEA.
  3. Open the file UserAgeCalculatorTest1.java. You'll see green "Run test" buttons next to line numbers. Press the one next to class UserAgeCalculatorTest1 and watch the test suite execute.