JetBrains / lincheck

Framework for testing concurrent data structures
Mozilla Public License 2.0
572 stars 33 forks source link

unit test implementation for repository #129

Closed marcela-cardona-s closed 1 year ago

marcela-cardona-s commented 1 year ago

Hi, I have an implementation question for a unit test.

How can I test this case, where I need to mock the repository because I'm not interested in actually saving it, but I'm interested in knowing what the concurrency behavior is when saving information.

Code:

image

Test:

image

Repository:

image

Entity:

image
ndkoval commented 1 year ago

Hi @marcela-cardona-s ,

It is unclear what behaviour you want to test and which contract should be ensured. Could you clarify, please?

marcela-cardona-s commented 1 year ago

I am trying to test the behavior of the launch coroutine that guarantees that there are no concurrency problems when saving to any database (repository), the idea is to be able to mock this component and when executing this test the injection does not work of dependencies given by @Mockk. What I hope is to be able to verify that there will be no concurrency problems when storing the information.

ndkoval commented 1 year ago

I am afraid this kind of test is not the case for Lincheck. I would suggest writing a stress test instead, which runs threads and calls the save function concurrently.