Data Input / Output and JUnit
[Practical 8 of 11]
This practical will examine how to build a simple read and write utility for your models. The example will be very simplistic but more complexity will be introduced for you to consider.
The Junit framework will be used to demonstrate the benefits of test driven development. Test driven development is a professional programming approach where a series of tests are first designed to ensure the behaviour of a method is as desired. The tests cover not just what should happen when all is working well but also what should happen when unexpected conditions are encountered.
The behaviour of the method is outlined prior to starting to write the actual code. Test methods are developed which identify if the behaviour of the actual method is as expected under certain conditions.
The benefits of test driven development are:
- If all the tests pass we know the behaviour of the method is as desired.
- If changes to the method are required at a later date, so long as all of the current test still pass, backwards compatibility of the method is assured.
- Team working is facilitated as team members can identify the series of tests for different components. As long as the whole team develop code against the agreed test conditions then all of the code produced by different developers should work when collated into one application / project.
- Generally code built against test conditions is robust well thought through and well structured.
The main drawback to test driven development is that it is time consuming in the initial development stages. However, the time investment is paidback through when code is revisited for enhancement or maintainance.
This practical will introduce a simple set of test conditions and some simple methods to satisfy that test. We will start by building a simple data reading package for csv files.