Generating unit test data for a complex database (EAV)

I am working with an outdated application that uses some of the famous / scary data modeling models known as EAV. This made the choice of a data generation strategy for use in unit testing DAL. What for? Because in addition to the normal Fk / Pk constraints between tables (which we use when possible), there are additional relationships / constraints that only the application layer knows and provides.

According to this article, the easiest data tests for recording and maintenance are those that rely on an external and static data set. However, it seems like trying to create a dataset that includes relationships already modeled β€œmanually” at my application level would be a DRY violation and a lot of PITA loading. On the other hand, using my application layer to generate test data becomes even more unpleasant because it violates the main directive (isolation) of unit tests, since application level regression can cause my DAL layer to throw dummy failures.

For this reason, I am inclined towards the option of a static dataset, that is, if others who have had to deal with the testing module of the EAV model can interact with alternatives.

Thank you very much.

+4
source share
1 answer

If the DAL is not responsible for enforcing certain application rules in the data warehouse, then there is no need to guarantee that the test data complies with these higher level rules. unit test only needs to make sure that the DAL applies the rules that are its responsibility - presumably things like staying within the database constraints, data types, etc. The data must only meet the prerequisites of the DAL itself in order to constitute a valid test case. Higher-level rules will be checked within the unit test application level, in which the DAL will be hatched or ridiculed. Under these assumptions, DAL tests are likely to have a fairly static dataset or one generated using trivial code.

It is possible that the "outdated" nature of the application makes it difficult, if not impossible, to unit test the application and the DAL levels separately. In fact, two layers in the aggregate would be a single (if complex) β€œunit”. In this case, it is acceptable (or possibly "valid" to have the correct word) for creating test data using the application layer as appropriate. Such a generation, in fact, will constitute even more test cases for the β€œunit” of the conglomerate. DAL errors due to application level regressions should be investigated as candidate errors in one, the other, or both layers. Any time spent dividing the two layers into separate blocks is likely to pay dividends in the long run.

+1
source

All Articles