Tuesday, January 31, 2012

TDD with JUnit : Interface definition

Using TDD, let us write a very basic Calculator, which has only one method "add".

We will use JUnit, an industry standard unit testing framework, to write the tests.

The first thing is to define the interface.

Create an interface called BasicCalculator in your src/org/confucius folder.
It looks like this:

 package org.confucius;  

public interface BasicCalculator {
public int add (int a, int b) throws Exception;
}



The 'add' method finds the sum of two integers.
It throws an Exception if there is any problem.

No comments: