CodeIgniter Forums
How proper unit test - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: How proper unit test (/showthread.php?tid=71866)



How proper unit test - Przem4S - 10-03-2018

Hello Smile

So, I have problem with testing.

Firstly - yes I read Testing Section in CI4 Docs

When I run simply "phpunit" in CI4 directory I have error:

Class `CodeIgniter\Test\CIUnitTestCase` not found in (...)\tests\_support\CIUnitTestCase.php on line 5

What's wrong? Composer update run with no-complications.


RE: How proper unit test - unodepiera - 10-04-2018

(10-03-2018, 01:46 AM)Przem4S Wrote: Hello Smile

So, I have problem with testing.

Firstly - yes I read Testing Section in CI4 Docs

When I run simply "phpunit" in CI4 directory I have error:

Class `CodeIgniter\Test\CIUnitTestCase` not found in (...)\tests\_support\CIUnitTestCase.php on line 5

What's wrong? Composer update run with no-complications.

All works fine for me.

composer create-project codeigniter4/framework:dev-develop mysuperapp
cd mysuperapp && composer install
ln -s ./vendor/bin/phpunit ./phpunit

Create the file tests/TestFoo.php:
PHP Code:
<?php

class TestFoo extends \CodeIgniter\Test\CIUnitTestCase
{
    
/**
     * @test
     */
    
public function testBar()
    {
        
$this->assertEquals(12);
    }


Execute the test with this command:
Code:
./phpunit tests/TestFoo.php --filter bar

[Image: Qto2Fkh.png]


RE: How proper unit test - Przem4S - 10-08-2018

Next try:

[Image: GzdOhLt.png]

PHPUnit for Windows installed.


RE: How proper unit test - unodepiera - 10-08-2018

(10-08-2018, 01:36 AM)Przem4S Wrote: Next try:

[Image: GzdOhLt.png]

PHPUnit for Windows installed.

Please, check my reply, all works fine:

composer create-project codeigniter4/framework:dev-develop mysuperapp
cd mysuperapp && composer install
ln -s ./vendor/bin/phpunit ./phpunit

And then:

./phpunit ....


RE: How proper unit test - Przem4S - 10-09-2018

@unodepiera

Your're running OS X, I'm Windows user - ln is not windows command, /vendor/bin/phpunit is not executable for windows.
But you navigate me to phpunit.bat and this resolve problem - thank you.

Proper command to run test for Windows:

PHP Code:
{framework_dir}\vendor\phpunit\phpunit.bat tests/TestFoo.php --filter bar 

I hope, that help other people with that same problem.

Thread to close Wink


RE: How proper unit test - Przem4S - 10-16-2018

I have another question about unit tests, on my computer many test fails:

Directory example, problem with path:

[Image: eAUxe8K.png]

Word-wrapping example:

[Image: PeasGxw.png]

I have many errors like that, any paths, any wordwrapping. How solve this?


RE: How proper unit test - puschie - 10-19-2018

yes - the most devs are unix users so the line ending ist \n
you use windows, so your line ending is \r\n

if you want to fix them, you need a unix system that execute the tests - or ignore them