Weird problem using JUnit in multi-thread environment

前端 未结 5 1042
耶瑟儿~
耶瑟儿~ 2020-12-16 05:03

I meet a weired problem when using JUnit in multi-thread environment. The following code should fail, but it actually pass in eclipse.

public class ExampleT         


        
5条回答
  •  青春惊慌失措
    2020-12-16 05:53

    As @abhin4v has pointed out, the exception in the new thread gets swallowed. You could try providing your own fail-method that syncronises with the top-level thread very much like in your example with get().

    But there's no need to use Futures, just write to a shared variable indicating failure and use newThreadId.join(). Apart from that, I'm not aware of any other way of solving this in plain JUnit.

提交回复
热议问题