Why do my tests throw random exceptions when I use the surefire setting parallel=methods
?
Why does SpringJUnit4ClassRunner not work with surefire parallel=methods?
That's because JUnit creates just one Runner instance per test class, which is used by multiple threads when using parallel=methods
. SpringJUnit4ClassRunner
creates just one TestContextManager
, which stores the test instance in an instance field, so it isn't thread safe.
When you use parallel=classes
everything should be fine, because then JUnit creates one runner with a dedicated TestContextManager
per thread.
I have filed a bug about that: https://jira.spring.io/browse/SPR-12421
© 2022 - 2024 — McMap. All rights reserved.