Hi,
you also may find the following Jython code helpful for calling JUnit Test Cases from Grinder 3:
Code:
from net.grinder.script.Grinder import grinder
from net.grinder.script import Test
from junit.framework import TestSuite
from junit.framework import TestResult
from mypackage.test import MyJUnitTestCase
class TestRunner:
def __call__(self):
# Turn off automatic reporting for the current worker thread.
# Having done this, the script can modify or set the statistics
# before they are sent to the log and the console.
grinder.statistics.delayReports = 1
# Creates a Test Suite.
suite = TestSuite(MyJUnitTestCase().getClass());
# Returns the tests as an enumeration.
tests = suite.tests();
# Iterate over the tests.
testNumber = 0
for test in tests:
testNumber += 1
testCase = Test(testNumber, test.getName()).wrap(suite)
testResult = TestResult()
testCase.runTest(test, testResult)
if testResult.errorCount() > 0:
grinder.statistics.success = 0
elif testResult.failureCount() > 0:
grinder.statistics.success = 0
It automatically "registers" all testXXX methods within a TestCase as Tests and displays it in the Grinder console. If the testXXX method fails or an error occurs, this is also reported to the Grinder statistics.
Wolfgang