multithreaded JunitTest

Noel Grandin noelgrandin at gmail.com
Mon Jun 1 00:47:09 PDT 2015



On 2015-06-01 09:33 AM, Miklos Vajna wrote:
> On Sat, May 30, 2015 at 04:47:56PM +0200, Lionel Elie Mamane <lionel at mamane.lu> wrote:
>> I fixed the underlying bug, but I would like to fix the test so that
>> it fails when one of the threads fails. I tried to not catch the
>> Exception, but that does not help. (I noticed the thread failure by
>> looking at workdir/JunitTest/dbaccess_complex/done.log )
>
> Can't you call org.junit.Assert.fail() in the catch block?
>

That's what the current code is doing, but org.junit.Assert.fail() just throws an AssertionError, so doing that inside a 
child thread is not useful.

The better way is to use ExecutorService, Callable, and Future.get(), see here for an example:

http://stackoverflow.com/questions/6546193/how-to-catch-an-exception-from-a-thread


More information about the LibreOffice mailing list