public class Tester
extends java.lang.Object
An example of the use of the Tester class follows.
void test() { Tester tester = new Tester(); String expected = "i = 42"; // expected results int i = 42;This will produce the following output.
tester.feature("MyClass.test()"); // optional tester.append("i = " + i); // gather test results tester.checkBuffer("MyClass.test()", expected);
tester.summary(); }
<<<<<<< Tester.java $Date: 1998/12/12 00:39:36 $ ======= $Date: 1998/12/12 00:39:36 $ >>>>>>> 1.1.1.1.2.1<<<<<<< Tester.java
expected: i = 42 actual: i = 42 MyClass.test(): Passed
Test completion matrix: MyClass.test(): Passed
0 out of 1 tests were not completed. 0 out of 1 tests failed. 1 out of 1 tests passed.
All tested completed and all Passed! Wed Sep 11 16:32:30 1996
Constructor and Description |
---|
Tester()
This constructor creates a Tester that only writes to System.out and
not to a file.
|
Tester(java.lang.String fileName)
This is the full constructor for the Tester class.
|
Modifier and Type | Method and Description |
---|---|
void |
append(java.lang.String str)
Appends a string to the end of the internal buffer.
|
void |
appendln(java.lang.String str)
Appends a string to the end of the internal buffer and adds a
linefeed at the end of the supplied String.
|
java.io.PrintWriter |
bufferStream()
Returns a PrintWriter that prints to the internal buffer.
|
boolean |
check(java.lang.String feature,
java.lang.String expected,
java.lang.String actual)
Compares the expected and actual results, decides if the test of
the identified feature passed or failed, and records the result.
|
boolean |
checkBuffer(java.lang.String feature,
java.lang.String expected)
Compares the expected results with the internal buffer, decides if
the test of the identified feature passed or failed, and records
the result.
|
void |
cleanUp()
Closes files.
|
void |
feature(java.lang.String feature)
Adds a feature to the anticipated tests that will be performed.
|
void |
featureResults(java.lang.String feature,
boolean pass)
Records the results of a test.
|
protected void |
finalize() |
java.io.PrintWriter |
outputStream()
Returns a PrintWriter that prints to the file and screen.
|
void |
print(java.lang.String str)
Prints a string to both System.out and to the test results file.
|
void |
println(java.lang.String str)
Prints a string plus a linefeed to both System.out and to the test
results file.
|
void |
resetBuffer()
Resets or empties the internal buffer.
|
void |
summary()
Prints a summary of all the features tested since the Tester was
created.
|
public Tester()
public Tester(java.lang.String fileName)
fileName
- the name of the file to record the test results inpublic void feature(java.lang.String feature)
feature
- the name of the feature to be testedcheckBuffer(java.lang.String, java.lang.String)
,
check(java.lang.String, java.lang.String, java.lang.String)
,
featureResults(java.lang.String, boolean)
public void featureResults(java.lang.String feature, boolean pass)
feature
- identifies the feature just testedpass
- the result of the test, true if the test passedcheckBuffer(java.lang.String, java.lang.String)
,
check(java.lang.String, java.lang.String, java.lang.String)
,
feature(java.lang.String)
public void cleanUp()
public void resetBuffer()
public void append(java.lang.String str)
str
- the String to append to the bufferappendln(java.lang.String)
public void appendln(java.lang.String str)
str
- the String to append to the bufferappend(java.lang.String)
public void print(java.lang.String str)
str
- the String to printprintln(java.lang.String)
public void println(java.lang.String str)
str
- the String to printprint(java.lang.String)
public boolean check(java.lang.String feature, java.lang.String expected, java.lang.String actual)
feature
- identifies the feature being checkedexpected
- the expected results of the testactual
- the actual results of the testcheckBuffer(java.lang.String, java.lang.String)
public boolean checkBuffer(java.lang.String feature, java.lang.String expected)
feature
- identifies the feature being checkedexpected
- the expected results of the testcheck(java.lang.String, java.lang.String, java.lang.String)
public void summary()
public final java.io.PrintWriter bufferStream()
public final java.io.PrintWriter outputStream()
protected void finalize() throws java.lang.Exception
finalize
in class java.lang.Object
java.lang.Exception