Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHPUnit in Laravel doesn't run when adding folders

I wanted to break my testing into their M, V, C folders. So I have:

/tests
    /models
    /views
    /controllers
    TestCase.php

As an example, I have a UsersControllerTest.php inside /controllers:

class UsersControllerTest extends TestCase {

    public function testSimple()
    {
        $this->assertTrue(true);
    }

}

When I run phpunit, all I get is Configuration read from PATH_TO_phpunit.xml. The problem arises when I add a test file inside a folder. If I move that test file to the root /tests folder, then everything works fine.

I tried to edit the phpunit.xml file to include:

<testsuites>
    <testsuite name="Application Test Suite">
        <directory>./app/tests</directory>
        <directory>./app/tests/controllers</directory>
    </testsuite>
</testsuites>

But it still didn't work

like image 276
Kousha Avatar asked Jul 24 '14 09:07

Kousha


People also ask

How do I run PHPUnit?

How to Run Tests in PHPUnit. You can run all the tests in a directory using the PHPUnit binary installed in your vendor folder. You can also run a single test by providing the path to the test file. You use the --verbose flag to get more information on the test status.

How to create test cases in Laravel?

Create Laravel Unit Test Case. While using PHPUnit, the first step is to create new test classes. These test classes are stored in the./tests/ directory of your Laravel application. Each test class is named as Test.

Why use PHPUnit?

PHPunit saves a lot of development time for developer because by writing unit tests, our code becomes less prone to defects. Other than unit testing, PHPUnit is also used with Selenium to test Web UI of any web application.


1 Answers

Solution was much simpler that I anticipated. All you have to do is add an asterix, *, to the end of the directory path inside phpunit.xml file:

<testsuites>
    <testsuite name="Application Test Suite">
        <directory>./app/tests/*</directory>
    </testsuite>
</testsuites>   
like image 176
Kousha Avatar answered Sep 28 '22 15:09

Kousha