Skip to main content

Tools - especially JUnit and Fit

Posted by wwake on December 25, 2003 at 3:22 AM PST

I'm reflecting on the most important tools I've been using this past year for my Java projects.

  • IntelliJ Idea - A fine IDE. My current default.
  • Eclipse - I've used it some, and found it a little clunkier than IntelliJ's. But I plan to move toward it more this coming year.
  • P4 - Perforce source control system. It's free for a single user, and does a nice job.


I've used two primary testing tools:

  • JUnit - for unit testing.
  • Fit - for system/acceptance testing.

JUnit is a simple unit testing framework. Suppose we're testing the Stack object. Here's an example test. The framework will locate the method via reflection (it treats methods starting "test" as tests):


import junit.framework.*;



public void TestClass extends TestCase

{

   public void testSomething() {

     Stack stack = new Stack();

     stack.push("Test string");



     String result = stack.pop().toString();



     assertEquals("Expected last value pushed", "Test string", result);

   }

}


(This test case fits a pattern I call "Arrange, Act, Assert": it sets up data, calls a method under test, and then verifies that it worked as expected.)

JUnit lets you create setUp() and tearDown() methods that will be called before and after each test method in a file. It has a number of other assertion methods (assertTrue, assertNull, etc.)


Fit is a tool for higher-level testing, available from fit.c2.com. It allows a Customer or tester to write tests in a spreadsheet (a very familiar interface). The tests are exported to HTML, and fit reads and runs them.

I typically use fit with a program known as FitNesse. FitNesse is a standalone wiki that knows how to run fit tests, either individually or in suites.

I can't create tables in this blog, so you'll have to use some imagination. But a fit test might look like this:


myprog.fit.NameFixture

in           formatted()

Joe Fish        Fish, Joe

John H. Doe      Doe, John H.

Queenie         Queenie

Dodge, B. R.      Dodge, B. R.

Fit has a number of builtin test classes that you can extend.


Both these testing tools can help change how you look at tests. They're both good additions to your set of tools

Happy new year to all! --Bill

Related Topics >>