Wednesday, October 21, 2009

Building a Testing Tool








Building a Testing Tool


In this lesson, you will build a testing tool similar to JUnit. I'll refer to this tool as TestRunner, since that will be the primary class responsible for executing the tests. The tool will be text-based. You will be able to execute it from Ant. Technically, you don't have to build a testing tool using TDD, because it's not intended to be production code. But there's nothing that says you can't write tests. We will.



JUnit requires a test class to extend from the class junit.framework.TestCase. In TestRunner you will use a different mechanism than inheritance: You will use Java annotations to mark a class as a test class.


Getting started is the toughest part, but using Ant can help. You can set up an Ant target to represent the user interface for the test. If not all of the tests pass, you can set things up so that the Ant build fails, in which case you will see a "BUILD FAILED" message. Otherwise you will see a "BUILD SUCCESSFUL" message.








    No comments: