assertEqual showing the actual values
- asssertEqual
SimpleTest and its UnitTestCase class provides further methods for assertions with better error reporting. In the end they all report assertions but these others have better capabilities in providing details on the failures.
In our case we could use assertEqual method instead of the assertTrue method. This one should receive two values. One of them should be the expected value the other one the actual result. The library does not make a recommendation which is which, it treats the two values in the same way and only checks if they are equal or not.
<?php
require_once(dirname(__FILE__) . '/../../../tools/simpletest/autorun.php');
require_once(dirname(__FILE__) . '/../includes/mylib.php');
class TestOfAdd extends UnitTestCase {
function testAdd() {
$this->assertEqual(add(1,1), 2);
$this->assertEqual(add(2,2), 4);
$this->assertEqual(add(1,1,1), 3);
}
}
?>
Output:
{% embed include file="src/examples/php/simpletest/st03.txt)
With the last row being RED
As you can see there is now a better explanation of what failed.