S
S
sergealmazov2014-02-10 11:26:14
Database
sergealmazov, 2014-02-10 11:26:14

What are fixtures and migrations?

Why do we need a mechanism of fixtures and migrations?
What are the pros and cons?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2014-02-10
@sergealmazov

Fixtures are essentially test data. They are needed for unit testing. It can be both data in the database and regular files (usually 2 options, before and after processing, so to speak). Each time the tests are run, this data is used to establish the initial state of the system so that the tests always run predictably.
For functional testing (testing controllers, integration tests), fixtures are not used, although the essence is also similar there. To be honest, this is where opinions differ. Some say that even mocks cannot be used for functional tests, that is, the system in the process of executing tests completely creates the state that is necessary for other tests. For example, sequential execution of tests for adding an article and viewing it. Others prefer to set the state from scratch for each test case. In essence, this is similar to using fixtures, but the implementation is different. You have some kind of api for filling with data (say, a method that adds a user), and before executing the test case, the data is reset and filled with new ones. There are also pluses - you can parallelize the execution of tests. (but don't take my word for it)
Migrations are a mechanism for organizing the versioning of the project structure. You can write a migration to change the location of the static (images, change links in the database, etc.), or you add a new table/field. Usually complemented by a back migration that restores the original structure. Mandatory for teamwork or frequent changes in the organization of data in the project, in general, I would advise using them always.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question