Undefind withoutExceptionHandling()

999 views Asked by At

I'm trying to run my UnitTest on laravel 6 (windows 10) with the famous:

this->withoutExceptionHandling();

But I get this error:

Error: Call to undefined method Tests\Unit\ExampleTest::withoutExceptionHandling()

I didn't change any setting and of course it's being defined in:

Illuminate\Foundation\Testing\Concerns\InteractsWithExceptionHandling

I even tried:

"use Illuminate\Foundation\Testing\Concerns\InteractsWithExceptionHandling;"

But this still does nothing.

2

There are 2 answers

0
Mohammad.Kaab On BEST ANSWER

This is a simple testing file, and it should work fine.

<?php

namespace Tests\Unit;


use Illuminate\Foundation\Testing\Concerns\InteractsWithExceptionHandling;
use Tests\TestCase;

class ExampleTest extends TestCase
{
    use InteractsWithExceptionHandling;

    /**
     * A basic test example.
     *
     * @return void
     */
    public function testBasicTest()
    {
        $this->withoutExceptionHandling();

        $this->assertTrue(true);
    }
}
0
Blues Clues On

I know it is really old to answer, but just in case someone need it. It will return an error because you're using it inside the Unit Test instead of the feature test. You can use the $this->withoutExceptionHandling(); in feature tests but not in unit test.