3

Currently, I am trying to run some simple unit tests with phpunit on a laravel project with the command line phpunit tests/Unit/ExampleTest. But it is only running the first method. Anyone has a solution ? Thank you !

namespace Tests\Unit;

use PHPUnit\Framework\TestCase;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class ExampleTest extends TestCase
{
    /**
     * A basic test example.
     *
     * @return void
     */
    public function testBasicTest()
    {
        $this->assertTrue(true);
    }

    /**
     * An other basic test
     *
     * @return void
     */
    public function secondTestBasicTest()
    {
        $this->assertTrue(true);
    }

    public function basicTest(){
        $response = $this->action('GET', 'DepartementsController@display', ['id' => 1]);
        $view = $response->original;
        $this->assertEquals(1, $view['$dpt->iddepartement']);
    }
}

1 Answer 1

9

PHPUnit by default launches only methods beginning with test prefix, so secondTestBasicTest and basicTest do not fall under that condition. You can explicitly annotate your tests as @test in PHPDoc to override this behavior:

/**
 * @test
 */
public function basicTest() {
    ...
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, you are a life saver !
Also, keep in mind your class name should be ended with the "Test" word.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.