A test case defines the fixture to run multiple tests.
To define a test case
- implement a subconcept of TestCase
- define instance variables that store the state of the fixture
- initialize the fixture state by overriding setUp
- clean-up after a test by overriding tearDown.
Each test runs in its own fixture so there can be no side effects among test runs.
Here is an example:
define MathTest extends TestCase [
fValue1 typeof Real
fValue2 typeof Real
: create ( $name typeof String ) [
super.create($name)]
: setUp() [
/fValue1= 2.0
/fValue2= 3.0]]
For each test implement a method which interacts with the fixture.
Verify the expected results with assertions specified
by calling assert with a boolean.
: testAdd [
result= fValue1 + fValue2
return .assertTrue(result == 5.0)] typeof String
The tests to be run can be collected into a TestSuite. mn8Unit provides
different test runners which can run a test suite and collect the results.
A test runner either expects a static method suite as the entry point to get a test to run or it will extract the suite automatically.
static : suite [
$suite typeof TestSuite( "Infos from this suite" )
$mathTest typeof MathTest
suite.addTest( $mathTest );
return $suite;]
Methods inherited from: Concept
cloneConcept, extendsConcept, fromXML, getAllInheritedConcepts, getConceptAttribute, getConceptAttributeField, getConceptAttributeFields, getConceptAttributes, getConceptConstructors, getConceptElement, getConceptElementField, getConceptElementFields, getConceptElements, getConceptLabel, getConceptMethod, getConceptMethods, getConceptOperators, getConceptType, getErrorHandler, getInheritedConcepts, getResourceURI, hasConceptAttribute, hasConceptElement, hasConceptMethod, hasPath, isHidden, loadContent, setConceptLabel, setErrorHandler, setHidden, setShowEmpty, showEmpty, toTXT, toXML, setResourceURI |
|
Methods inherited from: Assert
assertEquals, assertEquals, assertNil, assertNil, assertNotNil, assertNotNil, assertTrue, assertTrue, fail, fail, failNotEquals |
|
Methods inherited from: Test
|
Label: | fName |
Type: | String |
Is Static: | false |
Is Hidden: | false |
Is Multi: | false |
Show Empty: | true |
This element hold a name of the test case
Parameters: |
$name : | The name of test case |
|
Constructs a test case with the given name.
Constructs a test case without name.
Counts the number of test cases executed by run($result typeof TestResult).
Creates a default TestResult concept
Gets the name of a TestCase
A convenience method to run this test, collecting the results with a
default TestResult concept.
Runs the test case and collects the results in TestResult.
Runs the bare test sequence.
Override to run the test and assert its state. Returns the assert fail message.
Sets the name of a TestCase
Sets up the fixture, for example, open a network connection.
Tears down the fixture, for example, close a network connection.
Returns a string representation of the test case