JUnit terminates child threads

前端 未结 6 833
没有蜡笔的小新
没有蜡笔的小新 2020-12-01 13:04

When I test the execution of a method that creates a child thread, the JUnit test ends before the child thread and kills it.

How do I force JUnit to wait for the chil

6条回答
  •  佛祖请我去吃肉
    2020-12-01 13:31

    The basic technique that @Eyal outlined is what ConcurrentUnit is intended for. The general usage is:

    1. Spawn some threads
    2. Have the main thread wait or sleep
    3. Perform assertions from within the worker threads (which via ConcurrentUnit, are reported back to the main thread)
    4. Resume the main thread from one of the worker threads once all assertions are complete

    See the ConcurrentUnit page for more info.

提交回复
热议问题