Ranx99's avatar

Is this considered as a unit test?

I am trying to understand the different between a unit test and a feature test: lets say I am trying to test the password reset notification:

PasswordResetNotificationTest.php

/** @test */
public function is_pushed_to_a_queue()
{
    Queue::fake();

    $user = factory(User::class)->create();

    $user->notify(new ResetPassword('secret-token'));

    $this->assertEquals(1, Queue::size());
}

/** @test */
public function it_sends_an_mail()
{
    Notification::fake();
    $user = factory(User::class)->create();

    $user->notify(
        new ResetPassword('secret-token')
    );

    Notification::assertSentTo($user, ResetPassword::class, function ($notification, $channels) use ($user) {
        $mailData = $notification->toMail($user)->toArray();
        $this->assertEquals('password rest email subject', $mailData['subject']);

        return in_array('mail', $channels);
    });
}

Are these tests considered as a unit tests or feature tests?

0 likes
1 reply
Tray2's avatar
Tray2
Best Answer
Level 74

I would say they are feature tests.

A unit test is more a single method test.

    /**
    * @test
    */
    public function name_property_returns_the_authors_last_name_and_first_name()
    {
        $author = factory(Author::class)->create([
            'first_name' => 'Robert',
            'last_name' => 'Jordan'
        ]);

        $this->assertEquals('Jordan, Robert', $author->name);
    }
2 likes

Please or to participate in this conversation.