简体   繁体   中英

Is Java org.junit.Assert thread safe?

I want to verify if assert, and assertEquals is thread safe or not. I am under the understanding that it is not, as I believe I am running into race conditions wile using it for my JUnit tests. There are other ways I can go about verifying results of course. Its just simply out of convenience that I am using this function. I have looked at http://junit.sourceforge.net/javadoc/org/junit/Assert.html for reference, and there's no mention of any internal synchronization, or locking. Thanks.

For any reasonable implementation, and the one I randomly googled, assertTrue and assertEquals are thread-agnostic themselves. Thread agnosticism is the usual state of the world.

For the values are changing then, for the Object overload, equals on the expected object will need to be thread-safe and necessarily the values from toString may be different.

The fail message is passed via a String to the simple AssertionFailedError , which all looks in order, although Throwable is not safe from unsafe publication (not much mutable is).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM