D
D
dedmagic2018-12-24 11:25:04
Software design
dedmagic, 2018-12-24 11:25:04

How to test top-level business logic?

Let me formulate the question with a specific example.
Suppose that in order for the controller (MVC is just an example, the question is not related to any specific technology) to return the necessary data, you need to do the following:
1. Retrieve the data from the storage.
2. Filter them out.
3. Sort.
4. Select a page to display (pagination).
Each of these four elementary actions is very easy to cover with unit tests.
But still, somewhere there must be code that will call these methods sequentially and generate data for transmission to the Presentation Layer.
Question: where should this code be located?
1. If in the controller, we get the ease of testing business logic, but at the same time a Fat Stupid Ugly Controller (because it has business logic).
2. If we create such a method in the business logic layer, then it will be public, and elementary methods will be private. And because we have to test only public methods (class API), then we need to write tests for this overarching method, which is hell.
Where should this code be (in the context of unit testing)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny, 2018-12-26
Maltsev @maltsever

Hey! If you need to test the entire sequence together (points 1-4), then I would use functional tests, not unit tests. They are just needed in order to test how the feature works as a whole.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question