How to use Unit Testing v2.1.4 |
[eluser]a_h_abid[/eluser]
Apparently I see that there is a Unit Testing Library in v2.1.4. It is in user guide as well. http://ellislab.com/codeigniter /user-gu...sting.html So how do i use it? Where we put the test codes, In our main Controller or In a separate test file? If separate, how we use them?
[eluser]Otemu[/eluser]
Hi, The guide explains quite well how to use Unit Test so you should read though it again, however I try make things clearer for you So how do i use it? You use Unit Testing in your controller to see if a test returns an expected result, so for instance let say in your function you have a calculation to add 2 numbers 1+1 (example in guide) the expected result you would want is 2. So to achieve this follow the guide Quote:Like most other classes in CodeIgniter, the Unit Test class is initialized in your controller using the Then to display results use as follows in the guide: Quote:Generating Reports Where we put the test codes, In our main Controller or In a separate test file? You could put the tests in any controller but it would say it a much better practice to have a separate controller for tests Check out these resources below for further information and more advance features: video - Unit testing a real world Codeigniter application testing-codeigniter codeigniter_phpunit_and_netbeans unit-testing-for-codeigniter-phpunit-and-ciunit codeigniter-unit-testing
[eluser]a_h_abid[/eluser]
Hey thanks for the explanation & the links. I should check the resources now and try myself. One another question, is it just limited to test with controllers or can I also test with libraries (and maybe models)?
[eluser]Otemu[/eluser]
Hi, is it just limited to test with controllers mainly you would use it in your controllers however it not entirely limited to that or can I also test with libraries Since you can load libraries in your own custom created libraries you should be able to unit test them and maybe models You could test the returned result from your model within the controller, but I don't think you can unit test within the model itself. I think some of the links I provided have 3rd party tools to test directly within the model |
Welcome Guest, Not a member yet? Register Sign In |