Package ucb.test
Class TestFramework
- java.lang.Object
-
- ucb.test.TestFramework
-
public abstract class TestFramework extends Object
An abstract class that provides a rudimentary testing framework. Subtypes of TestFramework should override the runTests method to perform all desired tests, calling 'check' for each individual test to check the results, or 'failure' to indicate that a test has "blown up".
-
-
Field Summary
Fields Modifier and Type Field Description protected int
badCount
protected String
currentTestName
protected PrintStream
realStandardOutput
protected int
testCount
protected int
wrongCount
-
Constructor Summary
Constructors Modifier Constructor Description protected
TestFramework()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
captureStandardOutput()
Start storing up the standard output into a string.protected void
check(boolean test)
If TEST is tree, print "PASSED" message.protected void
check(Object correct, Object test)
Check that CORRECT is equal to TEST, using the "same" test below.protected void
check(String msg, boolean test)
If TEST is tree, print "PASSED" message.protected void
check(String msg, Object correct, Object test)
Check that CORRECT is equal to TEST, using the "same" test below.protected void
failure(String msg)
Report a "failure" (typically a test that blows up instead of producing a result).int
getBadCount()
Cumulative number of "bad" tests: those causing an exceptionprotected String
getCapturedOutput()
Return the captured output from the standard output.int
getErrorCount()
Cumulative count of tests that fail due to exceptions.int
getPassedCount()
Passed tests.int
getTestCount()
Cumulative number of calls to check.int
getWrongCount()
Cumulative number of calls to where the arguments were not the same.protected void
report()
protected void
restoreStandardOutput()
Stop capturing standard output, and revert to initial behavior.protected abstract void
runTests()
Execute all tests.static boolean
same(Object x, Object y)
True iff X equals Y in the sense that either 1) X and Y are arrays of the same length and their respective elements are == (if primitive) and (recursively) the same otherwise; or 2) X and Y are both null.static boolean
sameArrays(Object x, Object y)
protected void
setTestName(String name)
-
-
-
Field Detail
-
testCount
protected int testCount
-
wrongCount
protected int wrongCount
-
badCount
protected int badCount
-
currentTestName
protected String currentTestName
-
realStandardOutput
protected final PrintStream realStandardOutput
-
-
Method Detail
-
report
protected void report()
-
runTests
protected abstract void runTests()
Execute all tests. Should be overridden in subclasses.
-
setTestName
protected void setTestName(String name)
-
captureStandardOutput
protected void captureStandardOutput()
Start storing up the standard output into a string. You can later retrieve it with getCapturedOutput () and restore the initial standard output with restoreStandardOutput (). Throws away any previously saved output.
-
restoreStandardOutput
protected void restoreStandardOutput()
Stop capturing standard output, and revert to initial behavior.
-
getCapturedOutput
protected String getCapturedOutput()
Return the captured output from the standard output.
-
check
protected void check(boolean test)
If TEST is tree, print "PASSED" message. Otherwise indicate error.
-
check
protected void check(String msg, boolean test)
If TEST is tree, print "PASSED" message. Otherwise indicate error, printing MSG.
-
check
protected void check(Object correct, Object test)
Check that CORRECT is equal to TEST, using the "same" test below.
-
check
protected void check(String msg, Object correct, Object test)
Check that CORRECT is equal to TEST, using the "same" test below. Print MSG on error.
-
failure
protected void failure(String msg)
Report a "failure" (typically a test that blows up instead of producing a result). Use MSG as the explanation.
-
same
public static boolean same(Object x, Object y)
True iff X equals Y in the sense that either 1) X and Y are arrays of the same length and their respective elements are == (if primitive) and (recursively) the same otherwise; or 2) X and Y are both null. or 3) X.equals(Y).
-
getTestCount
public int getTestCount()
Cumulative number of calls to check.
-
getPassedCount
public int getPassedCount()
Passed tests.
-
getWrongCount
public int getWrongCount()
Cumulative number of calls to where the arguments were not the same.
-
getBadCount
public int getBadCount()
Cumulative number of "bad" tests: those causing an exception
-
getErrorCount
public int getErrorCount()
Cumulative count of tests that fail due to exceptions.
-
-