mlinhard / mockito

Automatically exported from code.google.com/p/mockito
0 stars 0 forks source link

UnfinishedStubbingException may be occurred when doAnswer().when(mock).method() and mock.method() is called in multi-thread environment. #301

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

UnfinishedStubbingException may be occurred   when 
doAnswer().when(mock).method() and mock.method() is called  in multi-thread 
environment. Please run attached code. 

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?
1.9.0-rc1, windows 7

Please provide any additional information below.

Original issue reported on code.google.com by mason....@gmail.com on 12 Dec 2011 at 12:31

Attachments:

GoogleCodeExporter commented 9 years ago
If think you are misusing the API. The sample code does not really say what 
does your code actually look like, it doesn't look like you are using the API 
in a correct way.

However I would recommend you to first prepare all the stubbing before passing 
mocks to different threads.

Also you should have asked us on the mailing list, instead of reporting a bug 
here.

Original comment by brice.du...@gmail.com on 12 Dec 2011 at 1:36

GoogleCodeExporter commented 9 years ago

Original comment by brice.du...@gmail.com on 9 Mar 2012 at 11:04

GoogleCodeExporter commented 9 years ago
Take a look at the FAQ. Stubbing or verifying concurrently does not make sense 
because it always lead to random results. Also, the mockito API cannot 
guarantee thread safety for stubbing and verification because of they way the 
DSL is designed.

As Brice mentions: feel free to use mocks concurrently, however prepare (stub) 
them *before* the concurrency starts.

Hope that helps! 

Original comment by szcze...@gmail.com on 11 Mar 2012 at 7:59