joshuahornby's avatar

Which test is actually testing the most?

Quick question, both these tests return green and I was just wondering which method everything prefers. For the record I am using the TestDummy package.

    /** @test **/
    public function intergrationTestOne()
    {
        $content = Factory::times(3)->create('App\Models\Content');

        $data = $this->repository->getAllContent();

        $this->assertCount(3, $data);

    }


    /** @test **/
    public function contentRepositoryShouldGetAllContent()
    {
        $repo = Mockery::mock('App\Repositories\ContentRepository');
        $repo->shouldReceive('getAllContent')->once()->andReturn('foo');
        $this->assertEquals('foo', $repo->getAllContent());
    }

I understand one is more a integration test, but is there a place in your app for both of them? In my head currently I prefer the Mockery style test.

0 likes
1 reply
JarekTkaczyk's avatar

The 2nd isn't testing anything. You're creating a mock and calling the method on the mock. Mocks are used to replace peers (dependencies and alike). You don't mock the class under test.

Please or to participate in this conversation.