History of bitUnitPackage

The bitUnit package is an integration of [http://simpletest.sourceforge.net|simpletest] into bitweaver. This package should only be active during development, since runnings testsuites will may take a lot of resources - once adding test code to the packages becomes common practice.

In order to make it as easy as possible to add test suites to bitweaver bitUnit adds features to bitweaver
# It searches the bitweaver installation for directories named test
# In these directories it finds ''.php'' files that start with ''test'' (case insensitive).
# These files are then added to simpletest datastructures for execution.
# After the test are executed the results are extracted and presented in a smarty template.

The bottom line is that if you whant to add a test for a package (or any other code in bitweaver) you only need to put properly named files in properly named directories.

-=Simple example=-

To start writing test the best way is to look in the simple test [http://simpletest.sourceforge.net|manual]. This is however a quick intro for writing tests:

Some points to remember for test classes:
# The test scripts need to include the script they will be testing (obviously).
# Create one test class per test script, the class name being the same as the file name.
# All test classes must extend class UnitTestCase (directly or indirectly).
# All methods within the test class beginning with the letters "test" will be executed by

So, for our class, this is what the test class would look like:
{CODE(colors=>php)}<?php
// Get the class you're going to test
require_once('MyClass.php');
// Always extend the UnitTestCase class. There is no need to include/require the UnitTestCase, since this is taken care of by the test framework
// Always prefix the class name with 'Test'
class TestMyClass extends Test {
var $test; // this variable will hold our test class
var $testString; // this variable will hold a testValue

// Make initializations that will not change during the test
function TestMyClass() {
// setting up constant values will prevent failiures due to typos.
$this->testString ="testValue";
}

// This function is run before every test function
// Make the test case initialiaztion here.
setUp() {
$this->test = new MyClass();
}

// This function is run after every test function
// Release any dynamic resource here.
tearDown () {
$this->test = NULL;
}

// Testcases the methods all starts with test.

// Check if the initial value is 'not-set'
function testGetInitialValue() {
$this->assertTrue($this->test->getText() == "not-set");
}

// Set value and test that it sets
function testSetValue() {
$this->test->setText($this->testString);
$this->assertTrue($this->test->getText() == $this->testString);
}
}
?>{CODE}

Note that by the fact that we have a setUp and tearDown method there is no dependancies between the testcases.
Page History
Date/CommentUserIPVersion
01 Oct 2005 (20:21 UTC)
Corrected examples
Jan Lindåker81.229.122.2491
Current • Source
No records found