Monday, November 10, 2008

Task: First Steps Into Test Driven Development

From here on we be using TDD (Test Driven Development) methodology.

While writing test driven code, we first write a unit test for the code we are about to write, and then we write the actual code. The code is refactored till the test passes. This process continues until we have a working solution. Writing code thus, also means we write code piecemeal in an iterative manner (which is another good coding practice).

We will use JUnit 3.8 as the testing framework. You may need to download it if your IDE does not already have it.

For this task you will write a simple program which takes a text file as an argument along with another argument which specifies whether the user seeks a word count or a line count. based on what the user asked for, print either the word count or a line count of the text file.

Remember you have to do Test Driven Development, which means first write an empty (solution) class, then write a test to test one of the public methods of your class, then implement the method and refactor it till the test passes. Then write another test for another public method, and implement that method in the actual class... so on and so forth.

As a practice of the solution class is called FileStats, the test class will be called FileStatsTest. Also if we are writing a test method for a method called methodA(), then the nam of the test method will typically be testMethodA(). See documentation of JUnit 3.8 for more details.

All the test classes will reside in the test directory and will have the same package as the solution class.

Describe what you did, any problems that you may have faced and how you overcame them, in a blog post.

Leave a comment here after completing this task.


No comments: