I found the solution. There was a middleware "LogApiAccess" trying to log the request and response to database. I just disable it and the test case worked. $this->withoutMiddleware(LogApiAccess::class);