Why does SpringJUnit4ClassRunner not work with surefire parallel=methods?
Asked Answered
N

1

5

Why do my tests throw random exceptions when I use the surefire setting parallel=methods ?

Neon answered 12/11, 2014 at 9:1 Comment(0)
N
7

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

Neon answered 12/11, 2014 at 9:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.