How should I unit test threaded code?

后端 未结 26 1697
悲&欢浪女
悲&欢浪女 2020-11-22 04:09

I have thus far avoided the nightmare that is testing multi-threaded code since it just seems like too much of a minefield. I\'d like to ask how people have gone about test

26条回答
  •  無奈伤痛
    2020-11-22 04:25

    Have a look at my related answer at

    Designing a Test class for a custom Barrier

    It's biased towards Java but has a reasonable summary of the options.

    In summary though (IMO) its not the use of some fancy framework that will ensure correctness but how you go about designing you multithreaded code. Splitting the concerns (concurrency and functionality) goes a huge way towards raising confidence. Growing Object Orientated Software Guided By Tests explains some options better than I can.

    Static analysis and formal methods (see, Concurrency: State Models and Java Programs) is an option but I've found them to be of limited use in commercial development.

    Don't forget that any load/soak style tests are rarely guaranteed to highlight problems.

    Good luck!

提交回复
热议问题