Skip to main content

Feature/Unit Tests: Make them Work

Premium
3 min read

The next thing I usually check is whether the project has tests. It means I can try to modify the code and run the tests to check if I didn't break anything.

And we do have some tests here:

But when I try to run them, I get an error:


Configuring Unit/Feature Tests

Well, yeah, I don't see the tests/Unit folder. And don't get me wrong: it's totally fine NOT to have Unit tests, staying only with Feature tests. But the default Laravel comes with the example Unit test:

tests/Unit/ExampleTest.php:

namespace Tests\Unit;
 
use PHPUnit\Framework\TestCase;
 
class ExampleTest extends TestCase
{
/**
* A basic test example.
*/
public function test_that_true_is_true(): void
{
$this->assertTrue(true);
}
}

In this case, the code author has deleted that example test with the full folder of tests/Unit. It may be fine, but the problem is that testing is still configured to run tests from the tests/Unit folder, which doesn't exist anymore:

phpunit.xml

<testsuites>
<testsuite name="Unit">
<directory>tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory>tests/Feature</directory>
</testsuite>
</testsuites>

So, we have two choices here:

  • Either create a tests/Unit empty folder
  • Or, specify in...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (30 h 09 min)

You also get:

55 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

No comments yet…

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.