title: unit test for relationship in laravel Model
body: <p>I am new for laravel model unit testing.so please look and suggest me what i am doing wrong.my code is given below.I have 2 models User and UserState.</p>
  
  <p><strong>Model User</strong></p>
  
  <pre><code>public function state()
      {
          return $this-&gt;hasOne('UserState');
      }
  </code></pre>
  
  <p><strong>Model UserState</strong></p>
  
  <pre><code>public function user()
  {
      return $this-&gt;belongsTo('User');
  }
  </code></pre>
  
  <p>now i am writing unit test for UserState. which is given below :</p>
  
  <p><strong>UnitTest UserStateModelTest</strong></p>
  
  <pre><code>public function testUserRelationIsTrue(){
      $user = new User();
      $user-&gt;username = 'testusername';
      $user-&gt;save();
      $this-&gt;assertEquals($user-&gt;user_id, $user-&gt;state-&gt;id);
  }
  </code></pre>
  
  <p>during test run by phpunit it generate error</p>
  
  <pre><code>Illuminate\Database\QueryException: SQLSTATE[23000]: Integrity constraint violation:
  1452 Cannot add or update a child row: a foreign key constraint fails
  </code></pre>