Reputation: 8020
In what order, does Laravel 5 call test cases inside a single class?
Are they called from top to bottom? Alphabetically? Can I specify the order?
Meaning, I want to test API calls starting from: POST ( creating an order ), GET ( reading that newly created order ), DELETE ( deleting that order ). It would be nice, If I could do that as 3 separate automatic tests, but I don't know, if they will be always executed int that specific order.
Upvotes: 2
Views: 659
Reputation: 26699
You can use @depends
annotation to ensure one test runs after another, but as @scrubmx pointed out, your tests should not relay on the order of the execution. Otherwise if your createOrder
tests fails, the rest of the test will not be executed. It's also harder to maintain a growing test suite if the data is created implicitly by another test case, and not explicitly in the one that makes operations on it, as you'll have more and more variations of the data you want to test against.
Upvotes: 1
Reputation: 2556
You should not relay on the order of the tests, instead do something like:
The data should not persist between tests, use the Illuminate\Foundation\Testing\DatabaseTransactions
or the Illuminate\Foundation\Testing\DatabaseMigrations
.
See more info: https://laravel.com/docs/5.2/testing#resetting-the-database-after-each-test
Upvotes: 3