Answer the question
In order to leave comments, you need to log in
What is the acceptable unit test speed?
Question from absolute beginner to people with experience in unit testing. One of my c# unit-tests in Visual Studio 2019, which loops around 2,000,000 iterations, lasts over a minute. Should I look for the reason for such a slow speed in the code of the program under test, or are unit tests basically a slow thing? How often do you have to deal with slow tests?
Answer the question
In order to leave comments, you need to log in
Tests are executed just like any other code. It is worth looking for the reason in the code. Although due to the lack of information about what the test does and how the code is written, it's just 50/50. I either guessed right or not (what to look for the reason for).
Questions to think about:
Do you really need all the objects that are created in setup for testing?
Is it possible to split one test into several?
To test complex objects, you can use Mock ( Moq ) - class layout.
And create a bunch of small unit tests than one big one.
That is, we want to test a function, we create a mock object with only the fields and properties used in this function.
> bypassing the loop in 2,000,000 iterations
Personally, I have not encountered the need to bypass the loop 2,000,000 times in tests, but if necessary, then there is a reason, then there is no way around it.
But I would take a closer look at the code
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question