I'm looking for a good unit testing for my web development. I'm using CodeIgniter for PHP, and I found this class on CodeIgniter's documentation, so here is my doubt:
Should I use 'Unit Testing Class' to test my code, or is going to be better to use PHPUnit or TOAST? Which is better and why?
I hope someone experienced can help me. Thanks!
With unit testing we test each component of the code individually. All components can be tested at least once. A major advantage of this approach is that it becomes easier to detect bugs early on. The small scope means it is easier to track down the cause of bugs when they occur.
PHPUnit is a unit testing framework for the PHP programming language. It is an instance of the xUnit architecture for unit testing frameworks that originated with SUnit and became popular with JUnit. PHPUnit was created by Sebastian Bergmann and its development is hosted on GitHub.
PHPUnit is a programmer-oriented testing framework for PHP. It is an instance of the xUnit architecture for unit testing frameworks. PHPUnit 9 is the current stable version. PHPUnit 10 is currently in development.
Unit testing is an approach to software development in which tests are written for each function in your application. If you are not familiar with the concept you might do a little googling on the subject. CodeIgniter's Unit Test class is quite simple, consisting of an evaluation function and two result functions.
In my opinion, I think it's better to use the standard PHPUnit for unit-testing.
Aside from that it has many nice features, your tests will be more consistent and it wont depend on CakePHP's unit testing class.
If in the future you decide that CakePHP does not suite your needs, you'll lose your unit tests. (or lets say, you'll have to migrate them, which is time)
If you are testing code, that depends on CakePHP(Controller, Model, etc), there's no problem to use CakePHP's tests, but for any other case, i think you should bet on the more-popular unit testing suite that can be used in every project (PHPUnit)
Happy testing :)
I haven't done any test with codeignitor's build in unit test class. but it looks like that this class provide only very simple assertion function (maybe it is because of the pursuit of lightweight) and the worst thing is, you have to mess up the testing code with your production code.
For unit test, it offers much more assertion functions, more features: like code coverage, selenium RC...etc. so it can extend your ability to ensure code quality. one more benefit is, it does not depend on any of your framework code, so you can easily migrate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With