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
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.
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.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With