If you have a big test suite with many errors, it can be difficult to navigate between them. I will show you a few tricks for dealing with this situation.
Imagine your application has many tests, some of which fail. Where would you start?
When running all tests, you see a lot of errors, so how do you even read them? If the failing tests are in the middle, you must scroll a lot in the terminal.
When running the tests, you can pass the --stop-on-failure
flag to stop running tests that fail on the first attempt. Then, you will see only the first failed test.
php artisan test --stop-on-failure
Not all tests are being run, and only one failed test is shown instead of two. Other tests are being shown as pending.
But, it often happens that fixing one test leads to all other tests being fixed as a consequence.
There could be cases when you see the failure but don't have the immediate solution, you don't have the time to fix that particular test, and you are okay with it failing for now.
Or you may be focusing on other pieces of code and want to skip that test for now.
On any test, you can use the skip()
method and, if needed, provide a message.
test('homepage contains table product', function () { $product = Product::create([ 'name' => 'table', 'price' => 100, ]); actingAs($this->user) ->get('/products') ->assertOk() ->assertSeeText($product->name);})->skip('temporarily unavailable');
Now, if you run the tests instead of two failed tests, one is marked as skipped.
The skipped test is marked with a minus icon in the tests listed.
I recommend doing that infrequently. But if you really need it as a last resource to pass all the tests quickly, you can skip some of the tests.
When using PHPUnit in the test, use $this->markTestSkipped()
and provide a message if needed.
class ProductsTest extends TestCase{ use RefreshDatabase; public function test_homepage_contains_table_product() { $this->markTestSkipped('temporarily unavailable'); $product = Product::create([ 'name' => 'table', 'price' => 123 ]); $response = $this->actingAs($this->user)->get('/products'); $response->assertOk(); $response->assertSee($product->name); }}