Welcome Guest, Not a member yet? Register   Sign In
How proper unit test
#1

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.
Reply
#2

(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]
Reply
#3

(This post was last modified: 10-08-2018, 01:38 AM by Przem4S.)

Next try:

[Image: GzdOhLt.png]

PHPUnit for Windows installed.
Reply
#4

(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 ....
Reply
#5

(This post was last modified: 10-09-2018, 01:00 AM by Przem4S.)

@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
Reply
#6

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?
Reply
#7

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
Reply




Theme © iAndrew 2016 - Forum software by © MyBB