CI Unit testing with Toast X (toast extended) |
[eluser]OliverHR[/eluser]
Original Code: ToastX (based on Toast project): https://sourceforge.net/projects/toastx/ Original Posts: ToastX - Controller Unit Testing Toast - Some help for Unit Testing, part II Im just posting a minor changes to Toast X: Quote:-Fix show all "Failing Tests" when running all controllers tests ZIP file attached to post. Hope this help to someone.
[eluser]XMadMax[/eluser]
Hi: Nice patch, I have installed in my framework, but, as I made with Toast, it's necesary to have it's own config file (config/toast_utest.php ?), to allow directory location of controllers and views. Also, I have find missing a assert function: assert_contents, to check if result contents a phrase or words inside. If you want I can send you my mod. Thanks, XMadMax
[eluser]OliverHR[/eluser]
Nop Xperez(Perez apellido??), no config file, if you want to change dir file just change Line 25 on toastx.php: Code: var $test_dir = '/test/'; I think the author did not want to be unobtrusive putting a CSS, config etc. I mean extra files. So just edit the controller and thats all. ---
[eluser]Ricardo Rodrigues[/eluser]
Hi there, I'm trying to use it but I cannot see how can I test a Controller... ![]() I have something like: Class Login_company extends Controller { function check_login () { } } How can I test the function "check_login"? Thanks in advance. Ricardo
[eluser]Ricardo Rodrigues[/eluser]
Can you be more specific? In example I can't see any controller function test: <?php require_once(APPPATH . '/controllers/test/ToastX.php'); class Example_tests extends ToastX { function Example_tests() { parent::ToastX(__FILE__); // Load any models, libraries etc. you need here } /** * OPTIONAL; Anything in this function will be run before each test * Good for doing cleanup: resetting sessions, renewing objects, etc. */ function _pre() {} /** * OPTIONAL; Anything in this function will be run after each test * I use it for setting $this->message = $this->My_model->getError(); */ function _post() {} /* TESTS BELOW */ function test_simple_addition() { $var = 2 + 2; $this->_assert_equals($var, 4); } function test_that_fails() { $a = true; $b = $a; // You can test multiple assertions / variables in one function: $this->_assert_true($a); // true $this->_assert_false($b); // false $this->_assert_equals($a, $b); // true // Since one of the assertions failed, this test case will fail } function test_or_operator() { $a = true; $b = false; $var = $a || $b; $this->_assert_true($var); // If you need to, you can pass a message / // description to the unit test results page: $this->message = '$a || $b'; } } // End of file example_test.php */ // Location: ./system/application/controllers/test/example_test.php */ |
Welcome Guest, Not a member yet? Register Sign In |