1

enter image description here

with the above consumer.class, when it runs in JUnit , it cannot receive message. but when running via main method directly, it works well. The following is the invoking code:

enter image description here

and the JUnit version is 4.10.

So, would anyone give some point? Thanks a lot in advance!

Of course, when running the two invocation, the JMS server has enough messages waiting for consumption.

Donald_W
  • 1,773
  • 21
  • 35
rmn190
  • 611
  • 1
  • 9
  • 19

1 Answers1

3

since your testMq() method just registers a listener and doesn't block the test thread, the test case will just stop. try adding Thread.sleep(10000) after the listener is registered but before the test case ends...

Ben ODay
  • 20,784
  • 9
  • 45
  • 68
  • thanks a lot for answer. with the main method, there is no explicit block. so the question is, why is blocked? and Junit not? – rmn190 Aug 10 '12 at 08:31
  • yep, apparently JUnits threading lifecycle behaves differently than just a main method: http://stackoverflow.com/questions/4540152/java-app-lifecycle – Ben ODay Aug 13 '12 at 23:58