laravelunit-testingexceptionphpunitlaravel-unit-test

Undefind withoutExceptionHandling()


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.


Solution

  • 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);
        }
    }