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 10 of 11  >>

Advertisement

Take ScriptDrivenAccountSuite for a Spin

To make it easy to try ScriptDrivenAccountSuite, I added a new recipe file, scriptdriven.srj, and a sample test script file, script.txt, to the Artima SuiteRunner distribution ZIP file in version 1.0beta6. If you have a release prior to 1.0beta6, please download the latest version of Artima SuiteRunner. Once you unzip the distribution ZIP file, you'll find scriptdriven.srj in the suiterunner-[release] directory. Here are the contents of scriptdriven.srj:

org.suiterunner.Suites=-s com.artima.examples.scriptdriven.ex1.ScriptDrivenAccountSuite
org.suiterunner.Runpath=-p "example"
org.suiterunner.Reporters=-g

In scriptdriven.srj:

When invoked via the previous command that specifies scriptdriven.srj as a command line parameter, Artima SuiteRunner will:

  1. Create a URLClassLoader that can load classes from the example directory, the directory specified via the recipe file's org.suiterunner.Runpath property.
  2. Via the URLClassLoader, load class com.artima.examples.scriptdriven.ex1.ScriptDrivenAccountSuite, the class specified in via the recipe file's org.suiterunner.Suites property.
  3. Discover that com.artima.examples.scriptdriven.ex1.ScriptDrivenAccountSuite class is a subclass of org.suiterunner.Suite.
  4. Instantiatecom.artima.examples.scriptdriven.ex1.ScriptDrivenAccountSuite.
  5. Run the suite of tests by invoking execute on the com.artima.examples.scriptdriven.ex1.ScriptDrivenAccountSuite instance.
  6. Report test results via the graphical reporter, the reporter specified via the recipe file's org.suiterunner.Reporters property.

To see the ScriptDrivenAccountSuite in action, run the following command from the suiterunner-[release] subdirectory of the directory in which you unzipped the Artima SuiteRunner distribution ZIP file:

java -jar suiterunner-[release].jar scriptdriven.srj

When you execute the previous command, you should see results similar to those shown in Figure 2. Because the previous command doesn't set the ScriptFile system property, ScriptDrivenAccountSuite will use its default script file name, script.txt. This script file, which sits alongside scriptdriven.srj, contains 23 tests, six of which fail. The six failures are caused by a bug introduced intentionally into class Account to demonstrate how Artima SuiteRunner reports failed tests. If you fix this bug and rerun the previous command, you should get 23 successful tests and a satisfying green bar.



Figure 2. ScriptDrivenAccountSuite results for script script.txt

<<  Page 10 of 11  >>


Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2017 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us