Does unit test, which is basically a false confirmation of the smell?

I have a class that connects three other services specifically designed to make other services more modular, but the bulk of my unit test logic is in check. Is there a way to redesign to avoid this?

Python example:

class Input(object): pass class Output(object): pass class Finder(object): pass class Correlator(object): pass def __init__(self, input, output, finder): pass def run(): finder.find(input.GetRows()) output.print(finder) 

Then I have to mock input, output and search. Even if I make another abstraction and return something from Correlator.run (), it still has to be verified as a layout.

+6
python language-agnostic unit-testing tdd
source share
3 answers

Just ask yourself: what exactly do you need to check in this particular case? If this check does not rely on the fact that other classes are not dummy, then you are fine.

However, many bullying tends to smell like you are probably trying to test integration without actually doing integration. Therefore, if you assume that if a class passes the test using mocks, it will work fine with real classes, than yes, you need to write some more tests.

Personally, I do not write a lot of unit tests. I am a web developer, and I prefer functional tests that validate the entire application through HTTP requests, just like users do. Your case may vary.

+2
source share

There is no reason to use unit test only. Perhaps integration tests would be more useful for this case. Initialize all objects correctly, use the main class and validate (possibly complex) results. This way you will check interfaces, predictability of output, and other things that are more important on the stack. I used this before and found that something that is difficult to integrate probably has too many attributes / parameters or too complicated / erroneously formatted output.

+2
source share

With a quick look, it looks like the level of ridicule is getting big. If you are in a dynamic language (I assume that yes, since your example is in Python), I would try to build either subclasses of production classes with the most problematic methods, overridden and representing bullying data, so that you would get a mix of production and mock above the code. If your path to the code does not allow you to instantiate objects, I would try the monkey patch in the replacement methods that return the data layout.

Weather or not, this is the smell of code, also depends on the quality of the mocking data. Getting into the debugger and copying the known correct data into it or sniffing it from the network, my experience is the preferred way to ensure this.

Integration versus unit testing is also an economical question: how hard is it to replace unit tests with integration / functional tests? The larger the scale of your system, the more you can get with a mockery and, therefore, unit tests.

0
source share

All Articles