What is SimpleTest? What does assertTrue($b)
do in SimpleTest? Do PHP programmers use SimpleTest often to test their programs?
views:
47answers:
2It is a PHP unit test and web test framework. Users of JUnit will be familiar with most of the interface. The JWebUnit style functionality is more complete now. It has support for SSL, forms, frames, proxies and basic authentication. The idea is that common but fiddly PHP tasks, such as logging into a site, can be tested easily.
The assertTrue($b)
literally says that you believe that the value in $b should be a boolean true. There's a number of other conditions you could also claim. You run some code, with a given input, and after that, a variable (say a return from the function), should be a particular value, given the set of inputs.
PHPUnit is more popular and up to date (as SimpleTest hasn't had a new release for some time), though for testing Webforms, it's still very useful as PHPunit does not have good support for that. It's also said that Simpletest has better support for some of the more advanced techniques, called 'Mocking', replacing part of a class to test with something under your own control.
Using a unit-testing framework can help develop better code (see: Test Driven Development), and ensure that bugs do not creep into your code after it's been written (for example, if you make a small change to add new functionality, but you also add a problem for a piece of code). If you run unit tests frequently you can have some confidence that all the code you have that is being tested is still working as designed.
For one introduction to testing, and why it's a good idea, the PHPunit manual has a good page