Suppose there is such a method:

bool IsValid() { var argument = StaticClass.CurrentArgument; return argument > 0; } 

For him, there are unit tests that verify that the logic is working correctly. But the case is not covered when the method is pulled from different streams. So, is a test that checks thread safety - is it closer to a unit test or to an integration test? Also, if there is a well-known other type of tests suitable for this case, it would also be nice to know.

We will agree that thread safety is easily verified, let's say it will be achieved by adding a lock directly in this method.

My understanding is closer to integration, because the purpose of the test is to check not the business logic (its verification will be a consequence), but the use of the code in combat conditions.

Answering this question, it is probably important to understand how important thread safety is for a business, i.e. as far as business logic is concerned. And it seems that is not so significant. After all, a lock can be, for example, before calling the IsValid() method and everything will also work fine. But on the other hand, if we clearly state in the contract of a method that the method is thread-safe (for example, in the name of a method or documentation), we should probably test it here as a logical component of the method.

    1 answer 1

    The division of tests into modular and integration occurs according to the principle of whether external dependencies are used or not and how large a unit you are testing. External dependencies are databases, third-party web services, etc.

    If there are no external dependencies, this means that a) test setup is trivial, b) test runs very quickly.

    If external dependencies are present, it always means that you are testing the larger components of the code (i.e. the integration of different components among themselves).

    So tests that check thread safety are unit tests. (And if you suddenly want to test thread safety using external dependencies, think three times and discard it.)

    PS

    check not the business logic, namely the use of the code in combat conditions.

    Is business logic not used in combat conditions? :)

    • Used by But for example, when integrating testing, the emphasis on checking the business logic of specific methods is much less than when unit testing. Hence the question was born. Thanks for the answer! - Serg046
    • one
      @ Serg046 yes, but business integration is still being checked in integration tests. Just not at the level of methods / classes, but of entire components or systems. To bind test definition to business logic is incorrect. It's my pleasure! - andreycha