Welcome Guest, Not a member yet? Register   Sign In
Intended use of the Unit Testing built in to CI
#1

[eluser]Frank V[/eluser]
In most framework unit testing implementations, you have a set of a tests and you execute those tests from a single [console] command. The tests run and a result is given. That result varies but generally it includes pass / fail.

CI's unit testing framework appears different and I have noticed an extensive collection of random tack-on-projects to either enhance or replace the CI unit testing framework.

My question is this: What is the intended work flow or use of the unit testing framework built in to CI?

I read the documentation; I get it. It's a simple class. But where does one utilize the class?

For example, do all the tests go in to a single "test" controller? Or do the tests get intermingled in to each controller? Then there is the question of the models and custom helpers...

Thanks for the guidance!

Regards,
Frank
#2

[eluser]Frank V[/eluser]
I realize that this is probably in the wrong place; if an admin could move it, I wouldn't mind...
#3

[eluser]Tominator[/eluser]
Hi man!

I really don't understant what you want to hear.

This is principe:
You probably make function, then test it by echoing return, then check if its the same as it should be, and if is, then you continue with your work.

Problems:
There might be an error, which you didn't found. When error appear, you have to retest whole class.

Solution:
Set unit testers into your functions, models, libraries, controllers and when something goes wrong, just start debuging and you easily find the error.

There is (as you said) lot of modifications and versions of Unit testing class, every got it from another angle, so you have to choose which is fine for you. I'm using CI's one with no problems.
#4

[eluser]Frank V[/eluser]
Hey, thank you for your reply.

I think I need to clarify my question. First, I'm very familiar with the concept of unit testing and (even) integration testing. Where I'm coming from is I have a project that I started in Django (Django Unit Testing). Things have been going well enough but since I'm still in the prototyping stage I wanted to look at CI. My current server is configured for PHP, so deploying in PHP will be simpler.

Generally, unit tests are meant to stick around. They are written and as development progressive, unit tests are used (for one thing) to ensure development regression doesn't turn up. So, in the course of my development I'll run the unit tests (all of them) contently. (Maybe 10 times in one hour)

That said, most unit test systems separate the code out from the main working code. This is commonly done in complementing classes. A user_model might have a user_model_test class. user_model_test will test user_model with as little dependency on outside classes as possible -- you'll pass in a dummy (or a simple) place holder.

Of course, CI's unit test methodology might be completely different from Django's, JUnit and the alike. What I'm looking for is an understanding of their model -- the intended use, if any.

Where would the tests be coded? How would the tests be executed?

Certainly correct me if I'm wrong but it sounds like you are describing a model where the unit test class might be utilized inside the user_model (to carry over the previous example). And any time the user_model is used, the tests (and output) are executed.

Now, alternatively I can see a test controller. And that test controller contains the unit test tests. And inside the test controller you might have n number of tests.

For example:

Code:
<?php

class test extends Controller {

    function test()
    {
        parent::Controller();
        $this->load->library('unit_test');
    }

    function index()
    {
        $this->all();
    }
    function all() {
        $this->test1();
        $this->test_n();
        // ... as needed ...
    }
    
    function test1() {
        //performs test...
        $this->unit->run( $var_result, 1, 'test 1, etc, etc' );
        //performs test...
        $this->unit->run( $var_result, 2, 'test 2, etc, etc' );
        //performs test...
        $this->unit->run( $var_result, 2, 'test 2, etc, etc' );
        
        echo $this->unit->report();
    }
    
    function test_n() {
        // ...
    }
    
    // ... more tests ...
}

I'd then run a single test by going to: http://localhost/my-ci-app/index.php/test/test1

And I'd test all by going to either http://localhost/my-ci-app/index.php/test or http://localhost/my-ci-app/index.php/test/all


Hopefully this clarifies my question. Thanks again!

Regards,
Frank
#5

[eluser]Tominator[/eluser]
I now understand you Smile

So you are right - unit test class is utilized inside the user_model. But you can turn it off via:
Code:
$this->unit->active(FALSE);

So you mix your working code with your testing code, and then (or before that) decide if the output should display or not.

Regards,
Tom
#6

[eluser]Frank V[/eluser]
Got it; thank you for your reply. I think understanding this really sheads light on why there are external modules built for unit testing CI. I've always avoid mixing test and app code.

Thanks,
Frank
#7

[eluser]Tominator[/eluser]
This is first unit testing class that I am using, but I think it got some pluses. With another classes you can test just results. With this one, you can test inputs, progress and output (but of course it makes a bit of chaos in your scripts).




Theme © iAndrew 2016 - Forum software by © MyBB