TDD

Main goal

The main purpose of this class is to show students the advantages of using IDE (i.e. IntelliJ IDEA) and following the concept of Test Driven Development – including both unit tests and mocking the behavior of objects. They will also have the opportunity to implement basic Java programs.

After laboratory students should be able:

Required for the lab

Knowledge of basic Java syntax. Understanding of concepts: IDE, unit testing, mocking, TDD, debugging, compilation.

TDD steps

  1. Create a String calculator with a method int sum(String numbers)
  2. The method can take 0, 1, or 2 numbers and will return their sum.
  3. An empty string will return 0.
  4. Example inputs: “”, “1”, or “1,2”.
  5. Start with the simplest test case of an empty string. Then 1 number. Then 2 numbers.
  6. Remember to solve things as simply as possible, forcing yourself to write tests for things you didn’t think about.
  7. Remember to refactor after each passing test.
  8. Allow the sum method to handle an unknown number of arguments/numbers.
  9. Negative numbers should be ignored.
  10. Example: “-1,2” returns 2.
  11. Calling sum with a sum bigger than 100 will throw an exception.
  12. Example “1, 100” throws IllegalArgumentException.