Back

Hey Laravel Developers

While writing assertions inside of your test cases you should be mindful about the order of how these assertions are made.

By the order what I mean is we should first check for more broader assertions and then narrow them moving forward.

For example, if we are testing a Post API, first we should verify that we received a 201 status code, then confirm if the response structure is correct, and then verify the database entries.

Here is an example of before and after assertions for a test case.

This helps in better debugging of test cases in case anything goes wrong

What do you think about this ??

image

1

66

  • No matching results...
  • Searching...

/ 1000

Sounds like good advice to me.

1

102

Yeah this also makes it easier to debug whenever any of the test cases fail, it makes it easier to guess what might go wrong if the tests are arranged this way!

85