|
|
|
Artima SuiteRunner |
Why |
Getting Started |
Tutorial |
Get Help |
Discuss |
Print |
Email |
First Page |
Previous |
Next
|
Suite Execution by Overriding execute
|
Advertisement
|
Account
ScriptDrivenAccountSuite tests class Account, a simple example class included in
the Artima SuiteRunner distribution ZIP file.
Once you unzip the distribution ZIP file, you'll find the source code for ScriptDrivenAccountSuite
in the suiterunner-[release]/example/com/artima/examples/scriptdriven/ex1 directory. You can also view the
complete listing in HTML. Because ScriptDrivenAccountSuite.java is
released under the Open Software License, you can use it as a template when overriding execute your own
custom Suite subclass.
Aside from a no-arg constructor that initializes the account balance
to zero, class Account has three methods in the public interface: deposit, withdraw,
and getBalance. The contract for these methods is shown in Figure 1.
Figure 1. The Account Class
com.artima.examples.account.ex6Account
|
public class Account Represents a bank account. |
| Constructors |
public Account()Construct a new Account with a zero balance.
|
| Methods |
public void deposit(long amount)Deposits exactly the passed amount into the Account.
|
public long getBalance()Gets the current balance of this Account.
|
public long withdraw(long amount) throws InsufficientFundsExceptionWithdraws exactly the passed amount from the Account.
|
Class ScriptDrivenAccountSuite consumes a test script, a file containing a sequence
of commands for testing class Account.
Each line of the file can contain at most one
test command, and each test command can occupy only
a single line. Blank lines are ignored.
A pound sign (#), and any characters appearing after it to the
end of the line, are also ignored, allowing for comments.
The four test commands are:
newAccount
getBalance
deposit
withdraw
newAccount Command
The newAccount commands causes ScriptDrivenAccountSuite to:
testStarting on the Reporter.
Account instance on which all subsequent commands (until the next newAccount) will operate.
testSucceeded on the Reporter.
testFailed on the Reporter.
newAccount command in a script file:
newAccount
getBalance Command
The getBalance command takes one argument, a long
expected return value. This command causes
ScriptDrivenAccountSuite to:
testStarting on the Reporter.
getBalance on the Account instance (created by the most recent newAccount command), and compare the return value with the expected value specified as the first argument to the getBalance command.
testSucceeded
on the Reporter.
testFailed on the Reporter.
Here's an example of a getBalance command in a script file:
getBalance 100
deposit Command
The deposit command has two forms. The first form
takes one argument, a long amount to deposit. This command will
cause ScriptDrivenAccountSuite to:
testStarting on the Reporter.
deposit on the Account instance,
passing in the specified amount to deposit.
deposit returns normally, invoke testSucceeded on the Reporter.
deposit throws an exception), invoke testFailed on the Reporter.
Here's an example of the first form of the deposit command in a script file:
deposit 10
The second form of the deposit command has two arguments,
a long amount to deposit and the fully qualified name of an expected
exception. This command will cause ScriptDrivenAccountSuite
to:
testStarting on the Reporter.
deposit on the Account instance,
passing in the specified amount to deposit.
deposit throws exactly the exception specified in the second argument,
invoke testSucceeded on the Reporter.
testFailed on the Reporter.
Here's an example of the second form of the deposit command in a script file:
deposit 1000 java.lang.ArithmeticException
withdraw Command
Like deposit, the withdraw command has two forms. The first form
takes one argument, a long amount to withdraw. This command will
cause ScriptDrivenAccountSuite to:
testStarting on the Reporter.
withdraw on the Account instance,
passing in the specified amount to withdraw.
withdraw returns normally and the returned amount is equal to the passed amount, invoke
testSucceeded on the Reporter.
withdraw throws an exception or returns the wrong amount), invoke
testFailed on the Reporter.
Here's an example of the first form of the withdraw command in a script file:
withdraw 20
The second form of the withdraw command has two arguments,
a long amount to withdraw and the fully qualified name of an expected
exception. This command will cause ScriptDrivenAccountSuite
to:
testStarting on the Reporter.
withdraw on the Account instance,
passing in the specified amount to withdraw.
withdraw throws exactly the exception specified in the second argument,
invoke testSucceeded on the Reporter.
testFailed on the Reporter.
Here's an example of the second form of the withdraw command in a script file:
withdraw 10 com.artima.examples.account.ex6.InsufficientFundsException
|
Sponsored Links
|