Package ucb.test

Class 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 Detail

      • testCount

        protected int testCount
      • wrongCount

        protected int wrongCount
      • badCount

        protected int badCount
      • currentTestName

        protected String currentTestName
      • realStandardOutput

        protected final PrintStream realStandardOutput
    • Constructor Detail

      • TestFramework

        protected TestFramework()
    • 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).
      • sameArrays

        public static boolean sameArrays​(Object x,
                                         Object 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.