Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use CodeIgniter's Unit Testing Class or PHPUnit/TOAST?

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!

like image 601
Fran Verona Avatar asked Feb 07 '11 12:02

Fran Verona


People also ask

Why do we use PHPUnit?

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.

What is PHPUnit testing?

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.

Is PHPUnit a framework?

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.

What is unit testing in CodeIgniter?

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.


2 Answers

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 :)

like image 59
Radoslav Georgiev Avatar answered Oct 12 '22 22:10

Radoslav Georgiev


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.

like image 42
fuyi Avatar answered Oct 12 '22 22:10

fuyi