D
D
Daria Motorina2020-09-03 13:53:42
PHPUnit
Daria Motorina, 2020-09-03 13:53:42

How to correctly cover the parsing and data generation module with tests?

It is hard to write testable code and good tests in practice, I want to rewrite the old module for parsing an Excel file and confusing data generation using the TDD method for training (so as not to write bad code, and then not know which way to approach it).

The more I analyze, the more difficult it is to understand what I can cover with tests at all, if important parts of the logic are hidden in such steps:
- make sure that the correct data structure is obtained from the file
- generate data according to a template that involves storing a large amount of intermediate data in the database, generation goes in several stages
- make sure that the final generated data is consistent according to a number of rules

From all this, I can understand how to write functional tests of the last step, if you generate valid data through fixtures, the remaining two stages will require a million classes to be recycled, working with files, working with the database.
It turns out that unit tests will not help much here if you start mocking everything, and without mocks they will turn into functional or end-to-end tests.

Can you please tell how you acted in similar situations or give a link to the material where such problems were solved?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
index0h, 2020-09-03
@glaphire

https://github.com/index0h/php-conventions#8-phpunit

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question