As it is discussed in the introduction, TDD has an approach of developing/implementing in a drive approach. This will let the test and implementation separate. Each implementation is driven by the test result. And the implementation finish when all the tests are passed. The test is considered as a design and all the implementation follow what has been stated in the test/design
There is a know life cycle that TDD has the following three phases Test/Design β Implement β Refactor. Each phases in TDD are represented in color. the color representation can be presented in two [Red, Green] or in some case presented as [Red, Yellow/Blue, and Green]
- Red/π΄:- Refers the state of design or refactor.
- Green/β : – Refers the state that all the implementation passed
The state transition in TDD are the following mainly
- β β π΄: – This is the that a test failed.
- π΄ β β :- This is a phase that the test passes after some refactor or maintenance or implementation of a failing test
- β β β : – This is a phase that a test fully passed.
The implementation of the TDD has got different phases and the detail of the phase as follow
- Creating a Test Function.
@Test
fun compareWeights(){
}
- Writing Assertion that is evaluation the expected against the actual.
@Test
fun compareWeights(){
assertEquals(expectedValue,actualValue);
}
- Act – refers the call of the created Test Function. But it might occur that the cal of the function might fail due to some declaration that we need to do before calling the test method. Some of the declaration might be using variables/parameters to store value or pass to the Test Method
@Test
fun weight comparing (){
val weight = Weight();
weight.weightCompare(5,10);
}
- Arrange – Running the test.
class Weight{
fun weightCompare(actualValue, expectedValue){
assertEquals(expectedValue,actualValue);
}
}
- Implementation – make a quick and dirty implementation – It should be passed at this stage.
- Refactor the implementation – to make the test nicer.