Thursday, April 29, 2010

Multiple JUnit 4.4 @RunWith annotations

Anybody know how to do this? JUnit 4.4?


@RunWith(MockitoJUnitRunner.class)
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"mocked_spring_tests.xml"})
public class MyTests
...


Eclipse complains "Duplicate annotation @RunWith"

4 comments:

  1. Did u get any solution to this, please email me - ramachandra.bhatt@gmail.com

    ReplyDelete
  2. was it possible to have the same annotation multiple times in the same class?

    ReplyDelete
  3. I played around with writing my own Runner implementation that delegated to the Spring and Mockito runners, but it was more complex than I anticipated. It's certainly possible, but personally was too difficult for me. So I just use the Spring runner and make due without the Mockito annotations.

    ReplyDelete
  4. If this requirement is specific to Mockito, you can try Powermock which allows to use mockito runners withour @Runwith annotation

    See http://stackoverflow.com/questions/2454473/junit-parameterized-tests-together-with-powermock-how

    ReplyDelete