@bencarter78 fails with what error message? Maybe your code is trying to grab the first survey thus the tests are asserting against the manual inserted survey instead of the test-created survey? More details of the failing test is needed in order to help you
Sep 4, 2015
3
Level 14
PHPUnit test passing then failing if dummy data is entered
Hi all
So I have something I don't understand and was hoping one of you laravel-ers could help me.
I have written a test to see if I can trash a model. This is what I have...
class SurveysControllerTest extends TestCase
{
use DatabaseTransactions;
function user()
{
return factory(\App\UserManager\Users\User::class)->create();
}
function survey()
{
return factory(\App\SurveyHound\Survey::class)->create();
}
/** @test */
function it_trashes_the_survey()
{
$survey = $this->survey();
$this->actingAs($this->user())
->visit('/surveyhound')
->see($survey->title)
->press('Delete')
->seePageIs('/surveyhound')
->see('You have successfully trashed the survey')
->dontSee($survey->title);
}
Now if I have an empty table in my database then the code passes, however if I go onto my web app and enter a new survey, then run my test again it fails.
Can anyone explain why this happens?
Be kind I'm new to testing!
Please or to participate in this conversation.