0

I want to create a series of tests that can run sequentially, the idea is that if the test before the one running does not pass, then all the suite shall not pass.

It sounds as anti pattern, but I need to test that user flow.

I tried with datasets but it restart the flow each time it runs the test.

apokryfos
  • 38,771
  • 9
  • 70
  • 114

2 Answers2

0

I am not sure if what I am going to share is what you are looking for. You have to use @depends, that will allow you to not run a test when the test it depends on did not pass.

This is the official documentation about it.

This is an example:

public function test_user_is_saved()
{
    // Test sending data to an endpoint stores the user
}

/**
 * @depends test_user_is_saved
 */
public function test_error_is_thrown_on_invalid_input()
{
    // Send invalid input (so validator fails)
}

If test_user_is_saved fails, test_error_is_thrown_on_invalid_input will not be run. You can chain this with any test.

matiaslauriti
  • 7,065
  • 4
  • 31
  • 43
0

Thanks!

After some search in the PRs of the official package I found that they are using ->depends() as pointed here so now I implemented that way.

Example:

<?php

use App\User;

it('is the first test', function () {
    $this->user = factory(User::class)->make();
    $this->assertTrue(true);

    return true;
});

// If I remove this test, it works fine.
it('depends on the first test', function ($arg) {
    $this->assertTrue($arg);
})->depends('it is the first test');

This is the official change log about it.