Symfony unit test best practice

I would like to know what are the best practices for controlling unit test fixtures.

I have the feeling that I have to write one foreach unit test fixture. I think that if I write too much unit test, the device will be too long. Then, if I want to change it, I will break some lights.

Now I'm looking for a way to record one fixture per unit test.

There are no problems in theory, I think. Tell me if I'm wrong.

My problem is how can I provide update updates. I do not want to change all fixtures if I change the database schema. This should be possible if any schema changes are made through migration.

Are there any tools for this?

+4
source share
1 answer

I was better off using a separate fixture file for each test file. This approach has several advantages:

  • The luminaires are independent , and changing them does not affect all tests, but only one.
  • The luminaires are smaller , since they do not need to cover each test case. This makes them easier to read.
  • It’s easier to see what the topic of the test case is, since each instrument file contains enough data.

The disadvantage is that with frequent changes to the database, you also need to update your fixtures. In many cases, this is not required because the new field is often used only with new tests. Otherwise, you can always automate the process (I do this using vim macros ).

Adding a new field should not violate existing IMHO tests. You should do all the tests still. If you need to change the behavior, you must first update your tests, make them unsuccessful, and make them skipped.

+5
source

Source: https://habr.com/ru/post/1341331/