The Artima Developer Community
Sponsored Link

Drive Your Unit Tests with Custom Scripts
How to Customize Suite Execution by Overriding execute
by Bill Venners
March 10, 2003

<<  Page 2 of 11  >>


A Test Scripting Language for Class Account

The Artima SuiteRunner distribution ZIP file includes several simple examples, most of which revolve around a very simple Account API in package com.artima.examples.account.ex6. The Account API includes two types, Account and InsufficientFundsException. Starting with release 1.0beta6, the distribution ZIP file also includes an example in package com.artima.examples.scriptdriven.ex1. This package contains two classes:

The purpose of the scripting language shown in this article's example is to demonstrate how to customize test execution by overriding execute in a Suite subclass. Although in real-world projects, it will rarely be useful to create a scripting language devoted to testing a single class, you may in some cases want to devise a more generic test scripting language for your system. A custom scripting language may, for example, be useful if you want non-Java programmers to write tests, or to provide a quicker way for Java programmers to write tests.

In addition, you may find it beneficial to automatically generate script- or data-based tests to replace or supplement tests written by hand in Java. You could, for example, create a Suite subclass that reads in automatically generated data in a table or XML format, and executes tests based on that data. The ScriptGenerator application included in this example generates a test script for class Account by making random deposits and withdrawals and checking for the expected result. By automating the generation of test data or script commands, you can broaden the coverage of your tests compared to hand-written tests.

<<  Page 2 of 11  >>

Sponsored Links

Copyright © 1996-2018 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use