Package junit.textui

Class TestRunner

  • All Implemented Interfaces:
    TestListener

    public class TestRunner
    extends BaseTestRunner
    A command line based tool to run tests.
     java junit.textui.TestRunner [-wait] TestCaseClass
     

    TestRunner expects the name of a TestCase class as argument. If this class defines a static suite method it will be invoked and the returned test is run. Otherwise all the methods starting with "test" having no arguments are run.

    When the wait command line argument is given TestRunner waits until the users types RETURN.

    TestRunner prints a trace as the tests are executed followed by a summary at the end.

    • Constructor Detail

      • TestRunner

        public TestRunner()
        Constructs a TestRunner.
      • TestRunner

        public TestRunner​(java.io.PrintStream writer)
        Constructs a TestRunner using the given stream for all the output
      • TestRunner

        public TestRunner​(ResultPrinter printer)
        Constructs a TestRunner using the given ResultPrinter all the output
    • Method Detail

      • run

        public static void run​(java.lang.Class<? extends TestCase> testClass)
        Runs a suite extracted from a TestCase subclass.
      • run

        public static TestResult run​(Test test)
        Runs a single test and collects its results. This method can be used to start a test run from your program.
         public static void main (String[] args) {
            test.textui.TestRunner.run(suite());
         }
         
      • runAndWait

        public static void runAndWait​(Test suite)
        Runs a single test and waits until the user types RETURN.
      • testFailed

        public void testFailed​(int status,
                               Test test,
                               java.lang.Throwable e)
        Specified by:
        testFailed in class BaseTestRunner
      • testEnded

        public void testEnded​(java.lang.String testName)
        Specified by:
        testEnded in class BaseTestRunner
      • createTestResult

        protected TestResult createTestResult()
        Creates the TestResult to be used for the test run.
      • pause

        protected void pause​(boolean wait)
      • main

        public static void main​(java.lang.String[] args)
      • start

        public TestResult start​(java.lang.String[] args)
                         throws java.lang.Exception
        Starts a test run. Analyzes the command line arguments and runs the given test suite.
        Throws:
        java.lang.Exception
      • runSingleMethod

        protected TestResult runSingleMethod​(java.lang.String testCase,
                                             java.lang.String method,
                                             boolean wait)
                                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • runFailed

        protected void runFailed​(java.lang.String message)
        Description copied from class: BaseTestRunner
        Override to define how to handle a failed loading of a test suite.
        Specified by:
        runFailed in class BaseTestRunner