|
|
||
William C. Wake's BlogDecember 2003 ArchivesTools - especially JUnit and FitPosted by wwake on December 25, 2003 at 03:22 AM | Permalink | Comments (2)I'm reflecting on the most important tools I've been using this past year for my Java projects.
I've used two primary testing tools: 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.NameFixturein 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 | ||
|
|