Welcome Guest, Not a member yet? Register   Sign In
My CI Unit Testing "Framework"... Help Me Improve It?
#1

[eluser]TaylorOtwell[/eluser]
I'm loving the CI framework, and I really like to unit test my models. I also like the simplicity of the CI unit testing class. However, I wanted organize my tests more so I didn't have this one monster test controller with all my tests.

So, I've come up with a solution for this and I'd like to get others opinions on it. I'll detail the parts below.

Test Controller

The test controller contains an array of "test fixtures", which are simply class names (without the _test_fixture suffix). It simply spins through each fixture and calls the "run_tests" method on the class.

Base Test Fixture Class (test_fixture.php)

Lives in application/test_fixtures.

This class contains the "run_all_tests" method which uses reflection to spin through all of the functions on the fixture and run each function (each function being a test).

Test Fixtures (fixture_name_test_fixture.php)

Lives in application/test_fixtures.

These classes extend the base Test Fixture class. The test fixtures are all of the tests for a logical group (usually a model for me). Each function name describes the test and is the name of the test. Each of the functions on the fixture will be called by the base test fixture class when the "run_all_tests" method is called. When calling the "run_all_tests" method, we pass in "$this" - the instance of the test fixture being run. Of course, the constructor and the "run_tests" method will not be called by the base class.


I think this is providing me with a much cleaner way to structure and organize tests, but I want to get your opinions on it!

I've attached the base test fixture class, a sample test fixture, and my test controller for you to look over.

Thanks for your opinions!




Theme © iAndrew 2016 - Forum software by © MyBB