• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A Decent Unit Test Template

[eluser]Kyle Johnson[/eluser]
Here is a decent landscape oriented unit-test template that I've been using. I've split off the individual tests into various other functions for my own sanity.

I'd love a better way to formulate the actual tests to have the name be equal to the test function, but that's not a big deal at this point.

Specifying set_test_items requires a super simple fix (https://github.com/EllisLab/CodeIgniter/issues/395)

This goes in my debug.php controller. http://localhost/index.php/debug/unit_tests
public function unit_tests() {
  $this->load->model(array('product_model','inventory_model', 'inventory_item_model'));
  $this->unit->set_test_items(array('test_name','test_datatype','res_datatype', 'result','line'));
  $str = '<tr>

private function _run_unit_tests() {
  echo '<table>';
  echo '<tr><th width="45%">Test Name</th><th>Test Type</th><th>Result Type</th><th width="15%">Result</th><th>Line</th></tr>';
  echo $this->unit->report();
  echo '</table>';
private function _unit_test_inventory() {
  $test = $this->product_model->is_serialized(5944);
  $expected = TRUE;
  $name = '$this->product_model->is_serialized(5944);';

private function _unit_test_permissions() {
  $test = $this->acl->is_logged_in();
  $expected = TRUE;
  $name = '$this->acl->is_logged_in();';
  echo $this->unit->run($test,$expected,$name);
  $test = $this->acl->user_has_permission("employee");
  $expected = TRUE;
  $name = '$this->acl->user_has_permission("employee");';

I tried to attach a screenshot, but was unable to at this time.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.