I love Adam's performances ("Resisting complexity" and "Crudy by design" is gold), but he's wrong about many details here. Let's take it in order. 1) Architecture consists of layers and components. Ideally, the components do not know anything about each other, and the layers have a certain orientation associated with moving away from input/output. Dependencies between them can be adjusted using dependency inversion. As a result, the business logic can be tested without using a database, framework, etc. Adam has no separation by layers in the example, he uses the framework on all layers. As a result, all dependency injections are meaningless, since they do not invert anything. Here you just need to use facades. They even have a built-in mock mechanism. 2) Development through mocks (London School), if used, is good because it allows you to systematize the implementation of useCase. The tests in it turn out to be more fragile, it's true, and I don't use it myself, but showing only the test results without the process itself means not showing the main advantage of this approach. 3) A large number of unit tests are obtained not because we have to write more of them, but because integration tests are expensive and we want to write fewer of them. A large number of unit tests are a consequence, not a goal. How would I test this useCase. I would create a chain of "Controller >> DTO + Interactor" classes. The first test would send a POST request and check the correctness of the DTO construction. The interactor would be a spy. The second test would start with Interactor and check that everything was saved correctly in the database. Since there is no complex business logic here, it is pointless to write unit tests here. Bottom line: the lack of layers and components in the architecture, as well as the lack of dependency inversion, made the example unrepresentative. The final tests turned out to be correct for such an architecture, but this has nothing to do with unit tests.
I'm huge fan of that guy and his programming style
I love Adam's performances ("Resisting complexity" and "Crudy by design" is gold), but he's wrong about many details here. Let's take it in order.
1) Architecture consists of layers and components. Ideally, the components do not know anything about each other, and the layers have a certain orientation associated with moving away from input/output. Dependencies between them can be adjusted using dependency inversion. As a result, the business logic can be tested without using a database, framework, etc. Adam has no separation by layers in the example, he uses the framework on all layers. As a result, all dependency injections are meaningless, since they do not invert anything. Here you just need to use facades. They even have a built-in mock mechanism.
2) Development through mocks (London School), if used, is good because it allows you to systematize the implementation of useCase. The tests in it turn out to be more fragile, it's true, and I don't use it myself, but showing only the test results without the process itself means not showing the main advantage of this approach.
3) A large number of unit tests are obtained not because we have to write more of them, but because integration tests are expensive and we want to write fewer of them. A large number of unit tests are a consequence, not a goal.
How would I test this useCase. I would create a chain of "Controller >> DTO + Interactor" classes. The first test would send a POST request and check the correctness of the DTO construction. The interactor would be a spy. The second test would start with Interactor and check that everything was saved correctly in the database. Since there is no complex business logic here, it is pointless to write unit tests here.
Bottom line: the lack of layers and components in the architecture, as well as the lack of dependency inversion, made the example unrepresentative. The final tests turned out to be correct for such an architecture, but this has nothing to do with unit tests.
Thanks for your great content.
Why don't you put title on videos, or even thumbnails containing titles?