I noticed that in the Example Tests, the two classes are built in.
Feature Test => use Tests\TestCase;
Unit Test => PHPUnit\Framework\TestCase;
What are the differences between the both? In which cases do you use one or the other?
I noticed that in the Example Tests, the two classes are built in.
Feature Test => use Tests\TestCase;
Unit Test => PHPUnit\Framework\TestCase;
What are the differences between the both? In which cases do you use one or the other?
PHPUnit\Framework\TestCase
This is the standard out-of-the-box parent for PHPUnit tests. It only has the functionality provided by PHPUnit.
It is best used when you want "true" unit tests that have no knowledge or scaffolding of Laravel. They are also much faster.
Tests\TestCase
This is a parent class for many kinds of tests (can be unit, integration, or feature) that depend on the Laravel app to function. These scenarios might include:
config()
)PHPUnit\Framework\TestCase
is the parent of Tests\TestCase
, so all of PHPUnit's standard functionality is also available.
You can use both! I use PHPUnit's TestCase when possible for unit tests, and Laravel's for integration and feature testing.