::xounit
Class TestRunner

Heritage:
::xotcl::Object
Direct Known Subclasses:
::xounit::TestRunnerTextUI, ::xounit::WebTestRunner,

Associated Test:
::xounit::test::TestTestRunner

Class TestRunner
superclass ::xotcl::Object,
TestRunner is a simple implementation of a test execution engine.
 Since most of the test handling code is actually in TestCase
 this class is very simple.  TestRunner just finds test classes,
 creates new instances and calls the run method on the new instance.
 TestRunner then stores the TestResults from the test runs in a
 results variable.
Variables
NameDefault ValueClassComment
results  ""  ::xounit::TestRunner
 a list of results from tests that have been run from this test runner
 
Methods
NameComment
findAllTestClasses {}   Finds all the subclasses of ::xounit::Test
passed {}   Returns true (1) if all tests that this test runner has run have passed
runATest {aTestClass}   runATest runs a test for one test class
runAllTests {{aNamespace ::}}   runAllTests finds all subclasses of ::xounit::Test, makes new instances of those classes, and runs those test instances
runTests {testClassList}   runTests runs the tests for a list of classes and appends the result to the end of the results list
   
Methods from ::xotcl::Object
#, ., ?, ?code, ?methods, ?object, abstract, copy, coverageFilter, defaultmethod, extractConfigureArg, filterappend, garbageCollect, get#, getClean#, hasclass, init, methodTag, mixinappend, move, profileFilter, self, setParameterDefaults, shell, tclcmd, traceFilter,
 
Instproc Detail

findAllTestClasses

Description:
 Finds all the subclasses of ::xounit::Test
Code:
  ::xounit::TestRunner instproc findAllTestClasses {}  {
   

        set allTestClasses ""

        #eval "lappend testClasses [ ::xounit::Test info subclass ]"
        set testClasses [ ::xounit::Test info subclass ]

        while { [ llength $testClasses ] != 0 } {

            set currentMultiClass [ lindex $testClasses 0 ]

            set testClasses [ lreplace $testClasses 0 0 ]

            set currentClass [ lindex $currentMultiClass 0 ]

            if { "$currentClass" == "" } continue

            lappend allTestClasses $currentClass

            #eval "lappend testClasses [ $currentClass info subclass ]"
            set testClasses [ concat $testClasses [ $currentClass info subclass ] ]
        }

        return [ lsort $allTestClasses ]
    
}

passed

Description:
 Returns true (1) if all tests that this test runner
 has run have passed.  Returns false (0) otherwise.
Code:
  ::xounit::TestRunner instproc passed {}  {
   
        
        ::xotcl::my instvar results

        foreach result $results {

            if { ![ $result passed ] } { return 0 }
        }

        return 1
    
}

runATest

Description:
 runATest runs a test for one test class.
 This process is followed:
 1) Create a new test instance from the ::xounit::Test subclass.
 2) Create a new TestResult from the new test instance newResult.
 3) Calls run on the new test instance with the new result instance.
 4) Return the test result.
Arguments:
Code:
  ::xounit::TestRunner instproc runATest {aTestClass}  {
   

        puts "TestRunner running test $aTestClass"

        cd [ [ $aTestClass getPackage ] packagePath ]

        if [ catch {

            set aTest [ $aTestClass new ]    
            set aResult [ $aTest newResult ]
            $aTest run $aResult

        } result ] {

            global errorInfo
            
            set message "$result\n"

            append message "Could not create test object from class $aTestClass"
            append message "\n"
            append message "$errorInfo"

            set aResult [ ::xounit::TestResult new -name $aTestClass ]
            $aResult addNewResult ::xounit::TestError  -name $aTestClass  -test init  -error "$message"
        }

        return $aResult
        
    
}

runAllTests

Description:
 runAllTests finds all subclasses of ::xounit::Test, makes new instances of
 those classes, and runs those test instances.  Optionally a
 namespace argument can be supplied that will limit the search
 for the subclasses to only that namespace. 

 Normally this will called this way:

 set runner [ ::xounit::TestRunner new ]
 $runner runAllTests
Arguments:
Code:
  ::xounit::TestRunner instproc runAllTests {{aNamespace ::}}  {
   

        foreach testClass [ my findAllTestClasses ] {

            if { [ string first $aNamespace $testClass ] != 0 } { continue }

            ::xoexception::try {
            
                ::xotcl::my lappend results [ ::xotcl::my runATest $testClass ]
            } catch { error e } {

                global errorInfo
                puts "Error running test [ ::xoexception::Throwable::extractMessage $e ]\n $errorInfo"
           }
        }
    
}

runTests

Description:
 runTests runs the tests for a list of classes and
 appends the result to the end of the results list.
Arguments:
Code:
  ::xounit::TestRunner instproc runTests {testClassList}  {
   

        ::xotcl::my instvar results

        foreach testClass $testClassList {

            ::xotcl::my lappend results [ ::xotcl::my runATest $testClass ]
        }
    
}