Hi,
The crux of my problem is that the new
JUnit 4.4. annotation, @RunAs, seems to have no effects whatsoever. Since in my Googling, I've found plenty of examples of code that uses the annotation, I must be doing something wrong.
I'm using Hibernate 3, Spring 2.5, and JUnit 4.4 What I am attempting to do is to write
unit tests for my Hibernate DAOs. Although in production they do not create their own transactional context (rather, a transactional context is created for them) I need them to create their own transactional context while running as unit tests.
To do this, it seems that the best approach is to annotation my unit tests using Spring's @Transactional annotation. In order for that to work, the tests need to run under SpringJUnit4ClassRunner. However, annotating my test class with
has no effect. When I debug the unit test, stop at a breakpoint, and look at the stack trace, I see that the test is always being run with JUnit's RemoteTestRunner.
It may be worth noting that I am running my JUnits within Eclipse (right-click on the class, and choose Run As -> JUnit Test).
I've tried running as other JUnit runners (@RunWith(Suite.class), for example) to see if that would have any effect; it did not. The tests still ran with RemoteTestRunner.
What on earth could I be doing wrong? At this point I'm not even concerned with creating the transactional boundaries; I just want to figure out why I can't tell JUnit what to Run As.
Code is below: