Unit Testing CodeIgniter with Simpletest - very few tests |
[eluser]mives29[/eluser]
Hello all! On our development team, we decided to give Unit Testing a try. We use Simpletest. However, it's been a tough road. After a week, I only have created 1 unit test that tests a certain helper file. That's it. The rest (controllers, models, views, libraries) don't have unit tests yet. And I plan to not test a majority of them. Views, for example, are too trivial to test, so I pass up on testing that. Next, the controllers. I plan my controllers to not do complex stuff, so that it only does passing of information between the models and the views. I'd move those more complex stuff to libraries or helpers. Now for my questions: 1) Am I doing it wrong? So far, there's nothing more that I can see that can be erroneous so it would need a unit test. Most of the stuff (right now) are just CRUD. 2) Do we really need to unit test controllers? Since a controller's job is just minor processing of data passed between View and Model, I find very little initiative in unit testing it. 3) If I use WebTestCase to test for controllers, would that be still considered a Unit Test? Or is it already an integration test? 4) Suppose you got me to test my controller, how would I test it? As far as I know, CI follows the Front Controller pattern through index.php, so how would I handle (mock?) that?
[eluser]Eric Cope[/eluser]
Its my opinion that unit testing is for functions, like models and libraries. For example, do your functions properly handle bad input. My specific example is my models check the inputs of type and size (in the case of strings) to make sure data is not truncated in the database. I am still trying to find a good method for testing controllers other than by hand. Any ideas?
[eluser]mives29[/eluser]
Using a webtestcase or Selenium seems to be the only practical way. Then just separate processing logic to other classes. This way, the controller's only use would be passing of data from the view to the model, and vice-versa.
[eluser]Eric Cope[/eluser]
has anyone extended the CI unit test class to include features like webtestcase?
[eluser]matt2012[/eluser]
I'm using the simpletest implementation from Eric Barnes http://ellislab.com/forums/viewthread/148850/ http://github.com/ericbarnes/codeigniter-simpletest/ If you set up a controller test (basically by doing a web test) you can do something like this Code: class test_homecontroller extends CodeIgniterWebTestCase Note that you need to use CodeIgniterWebTestCase not CodeIgniterUnitTestCase |
Welcome Guest, Not a member yet? Register Sign In |