Package ucb.test
Class TimedTestFramework
- java.lang.Object
-
- ucb.test.TimedTestFramework
-
public abstract class TimedTestFramework extends Object
An abstract class that provides a rudimentary testing framework. Subtypes of TimedTestFramework should call '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 int
outputLimit
protected PrintStream
realStandardError
protected PrintStream
realStandardOutput
protected int
testCount
protected int
wrongCount
-
Constructor Summary
Constructors Modifier Constructor Description protected
TimedTestFramework()
-
Method Summary
All Methods Static Methods Instance 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)
Check that TEST is true, printing PASSED or ERROR messages accordingly and updating test and error counts.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)
Check that TEST is true, printing either a PASSED message or or an ERROR message incorporating MSG accordingly and updating test and error counts.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).protected void
failure(Throwable e)
Report a "failure" from exception E.int
getBadCount()
Cumulative number of "bad" tests: those causing an exceptionprotected String
getCapturedError()
Return the captured output from the standard error output.protected 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.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)
protected void
setVerbosity(boolean verbose)
static String
toString(Object x)
-
-
-
Field Detail
-
testCount
protected int testCount
-
wrongCount
protected int wrongCount
-
badCount
protected int badCount
-
currentTestName
protected String currentTestName
-
realStandardOutput
protected final PrintStream realStandardOutput
-
realStandardError
protected final PrintStream realStandardError
-
outputLimit
protected int outputLimit
-
-
Method Detail
-
report
protected void report()
-
setVerbosity
protected void setVerbosity(boolean verbose)
-
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.
-
getCapturedError
protected String getCapturedError()
Return the captured output from the standard error output.
-
check
protected void check(boolean test)
Check that TEST is true, printing PASSED or ERROR messages accordingly and updating test and error counts.
-
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. Prints the message MSG if it is not.
-
check
protected void check(String msg, boolean test)
Check that TEST is true, printing either a PASSED message or or an ERROR message incorporating MSG accordingly and updating test and error counts.
-
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.
-
failure
protected void failure(Throwable e)
Report a "failure" from exception E.
-
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.
-
-