Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does SpringJUnit4ClassRunner not work with surefire parallel=methods?

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

like image 934
Bastian Voigt Avatar asked Nov 12 '14 09:11

Bastian Voigt


1 Answers

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

like image 153
Bastian Voigt Avatar answered Nov 14 '22 23:11

Bastian Voigt