This workshop is designed to help you start or improve your TDD skills.
This workshop is designed to help you start or improve your Test Driven Development skills.
The examples you will see in this workshop are designed to demonstrate the advantages and technicalities of TDD. The intention is to represent real-world scenarios, however sometimes that will not be possible in favour of simplicity.
Test Driven Development or Test First Development is a process that consists of turning the requirements of the software application into specific test cases (acceptance criteria) and then implement the source code.
This process uses the red/green/refactor pattern and consists of the following steps:
Repeat
Prerequisites
We will be using a few tools/frameworks to facilitate our job.
Tests serve 3 purposes:
To achieve proper documentation, a good starting point is to create naming conventions for the tests.
You can define your own conventions keeping in mind that the test methods should clearly identify:
Example with a traditional approach (simple JUnit):
test("sum: if both numbers are Positive returns positive number") {
...
}
Tests typically follow the AAA pattern:
Example:
test("sum: if both numbers are Positive returns a positive number") {
// Arrange
val a = 10
val b = 20
val calc = new Calculator()
// Act
val result = calc.sum(a, b)
//Assert
assert(result > 0)
}
Mocks and Stubs are used to facilitate testing by solving the problem of dependencies.
When the code you are implementing has a dependency, using this technique, you create a fake object that emulates that dependency. If you are required to define specific return values to emulate a certain scenario then you’ll need to use a stub otherwise you’ll simply use a mock.
Example:
var wallet = mock[Wallet]
var provider = mock[Provider]
var broker = new PaymentBroker(wallet, provider)
var wallet = stub[Wallet]
var provider = stub[Provider]
var broker = new PaymentBroker(wallet, provider)
(wallet.getBalance _).when().returns(balance)
(provider.isAvailable _).when().returns(true)
Feedback is one of the most important things in the development world, the sooner you get it the better.
Typically most of the feedback comes from the user/client of your software, but you should be getting it before you ship it.
There are plenty of tools out there that can help you with this. In this workshop we will be using the following:
Automation Server - Allows you to automate the test execution (Continuous Integration) and other routines associated with it (Continuous Delivery/Continuous Deployment). In this particular case we are using Travis CI.
You can check the current status of the workshop project by clicking the following badge:
Static Code Analyzer - Allows you to continuously inspect the quality of the code by detecting issues and providing suggestions to solve them. In this project we are using SonarCloud.
You can check the current status of the workshop project by clicking the following badge:
Kanban Board - Allows you to track your project’s work with a workflow visualization tool.