nickywan123
1 week ago
103
6
Laravel

php artisan test not passing a test case

Posted 1 week ago by nickywan123

I am new with TDD and tried to implement few test cases in my app.

ReadThreadTest:


class ReadThreadsTest extends TestCase
{
    use DatabaseMigrations;


    public function setUp():void{
        parent::setUp();
        $this->thread = factory('App\Thread')->create();
    }


    /**
     * A basic test example.
     * @test
     * @return void
     */
    public function a_user_can_view_all_threads()
    {
        
        $thread = factory('App\Thread')->create(); 

        $response = $this->get('/threads');
        $response->assertSee($thread->title);

      
    }

     /**
     * A basic test example.
     * @test
     * @return void
     */
    public function a_user_can_read_a_single_thread()
    {
        
        $thread = factory('App\Thread')->create(); 
        $response = $this->get('/threads/' .$this->thread->id); 
        $response->assertSee($this->thread->tiitle);
    }
      

    public function a_user_can_read_replies_associated_with_a_thread(){
        //Given a thread, a thread include replies
        //And that thread include replies,when we visit a thread page, we should see replies
        
        $reply = factory('App\Reply')->create(['thread_id' => $this->thread->id]);
        
        $this->get('/threads/'.$this->thread->id)
        ->assertSee($reply->body);

    }
}

When I run php artisan test, it shows all the test functions passed except for the last one (a user can read replies associated with a thread). It doesn't show any error so I am not sure why it is not passed. Can anyone give any pointers?

Please sign in or create an account to participate in this conversation.