Java Mailing List Archive

http://www.gg3721.com/

Home » user.jmock »

[jmock-user] Spurious Junit exceptions - Jmock the cause?}

Furtado, Murray

2008-02-21

Replies: Find Java Web Hosting

Author LoginPost Reply
Spurious Junit exceptions - Jmock the cause?}

Hi,

I have some unit test which inherits from the Spring convenience class AbstractTransactionalJUnit4SpringContextTests. This is used to allow autowired injection of spring beans and wrap each test within it's own transaction. The test cases uses Junit 4 annotations and I have many other tests which follow the same pattern which all execute fine. I have one test which uses Jmock 2.4.0 and when executing the test from an ant build, I get the following exceptions logged:

2008-02-21 13:36:09,438 [Thread-1841] INFO  ScriptRunner     -     [junit] Running test.dit.ops.caps.warehouse.payment.subscriber.TestMessageExceptions$1

2008-02-21 13:36:09,445 [Thread-1841] INFO  ScriptRunner     -     [junit] Testsuite: test.dit.ops.caps.warehouse.payment.subscriber.TestMessageExceptions$1

2008-02-21 13:36:10,337 [Thread-1841] INFO  ScriptRunner     -     [junit] Tests run: 2, Failures: 0, Errors: 2, Time elapsed: 0.898 sec

2008-02-21 13:36:10,343 [Thread-1841] INFO  ScriptRunner     -     [junit] Tests run: 2, Failures: 0, Errors: 2, Time elapsed: 0.898 sec

2008-02-21 13:36:10,344 [Thread-1841] INFO  ScriptRunner     -     [junit]
2008-02-21 13:36:10,344 [Thread-1841] INFO  ScriptRunner     -     [junit] Testcase: initializationError0(test.dit.ops.caps.warehouse.payment.subscriber.TestMessageExceptions$1):      Caused an ERROR

2008-02-21 13:36:10,345 [Thread-1841] INFO  ScriptRunner     -     [junit] Test class should have public zero-argument constructor

2008-02-21 13:36:10,345 [Thread-1841] INFO  ScriptRunner     -     [junit] java.lang.Exception: Test class should have public zero-argument constructor

2008-02-21 13:36:10,345 [Thread-1841] INFO  ScriptRunner     -     [junit]      at java.lang.reflect.Constructor.newInstance(Constructor.java:494)

2008-02-21 13:36:10,345 [Thread-1841] INFO  ScriptRunner     -     [junit]      at java.lang.reflect.Constructor.newInstance(Constructor.java:494)

2008-02-21 13:36:10,346 [Thread-1841] INFO  ScriptRunner     -     [junit] Caused by: java.lang.NoSuchMethodException: test.dit.ops.caps.warehouse.payment.subscriber.TestMessageExceptions$1.<init>()

2008-02-21 13:36:10,346 [Thread-1841] INFO  ScriptRunner     -     [junit]      at java.lang.Class.getConstructor0(Class.java:2678)

2008-02-21 13:36:10,346 [Thread-1841] INFO  ScriptRunner     -     [junit]      at java.lang.Class.getConstructor(Class.java:1629)

2008-02-21 13:36:10,347 [Thread-1841] INFO  ScriptRunner     -     [junit]
2008-02-21 13:36:10,347 [Thread-1841] INFO  ScriptRunner     -     [junit]
2008-02-21 13:36:10,347 [Thread-1841] INFO  ScriptRunner     -     [junit] Testcase: initializationError1(test.dit.ops.caps.warehouse.payment.subscriber.TestMessageExceptions$1):      Caused an ERROR

2008-02-21 13:36:10,347 [Thread-1841] INFO  ScriptRunner     -     [junit] No runnable methods
2008-02-21 13:36:10,348 [Thread-1841] INFO  ScriptRunner     -     [junit] java.lang.Exception: No runnable methods
2008-02-21 13:36:10,348 [Thread-1841] INFO  ScriptRunner     -     [junit]      at java.lang.reflect.Constructor.newInstance(Constructor.java:494)

2008-02-21 13:36:10,348 [Thread-1841] INFO  ScriptRunner     -     [junit]      at java.lang.reflect.Constructor.newInstance(Constructor.java:494)

2008-02-21 13:36:10,349 [Thread-1841] INFO  ScriptRunner     -     [junit]
2008-02-21 13:36:10,349 [Thread-1841] INFO  ScriptRunner     -     [junit]
2008-02-21 13:36:10,714 [Thread-1840] WARN  ScriptRunner     -     [junit] Test test.dit.ops.caps.warehouse.payment.subscriber.TestMessageExceptions$1 FAILED

2008-02-21 13:36:13,465 [Thread-1841] INFO  ScriptRunner     -     [junit] Running test.dit.ops.caps.warehouse.payment.subscriber.TestMessageExceptions$2

2008-02-21 13:36:13,475 [Thread-1841] INFO  ScriptRunner     -     [junit] Testsuite: test.dit.ops.caps.warehouse.payment.subscriber.TestMessageExceptions$2

2008-02-21 13:36:14,336 [Thread-1841] INFO  ScriptRunner     -     [junit] Tests run: 2, Failures: 0, Errors: 2, Time elapsed: 0.869 sec

2008-02-21 13:36:14,337 [Thread-1841] INFO  ScriptRunner     -     [junit] Tests run: 2, Failures: 0, Errors: 2, Time elapsed: 0.869 sec

2008-02-21 13:36:14,337 [Thread-1841] INFO  ScriptRunner     -     [junit]
2008-02-21 13:36:14,338 [Thread-1841] INFO  ScriptRunner     -     [junit] Testcase: initializationError0(test.dit.ops.caps.warehouse.payment.subscriber.TestMessageExceptions$2):      Caused an ERROR

2008-02-21 13:36:14,339 [Thread-1841] INFO  ScriptRunner     -     [junit] Test class should have public zero-argument constructor

2008-02-21 13:36:14,339 [Thread-1841] INFO  ScriptRunner     -     [junit] java.lang.Exception: Test class should have public zero-argument constructor

2008-02-21 13:36:14,340 [Thread-1841] INFO  ScriptRunner     -     [junit]      at java.lang.reflect.Constructor.newInstance(Constructor.java:494)

2008-02-21 13:36:14,340 [Thread-1841] INFO  ScriptRunner     -     [junit]      at java.lang.reflect.Constructor.newInstance(Constructor.java:494)

2008-02-21 13:36:14,341 [Thread-1841] INFO  ScriptRunner     -     [junit] Caused by: java.lang.NoSuchMethodException: test.dit.ops.caps.warehouse.payment.subscriber.TestMessageExceptions$2.<init>()

2008-02-21 13:36:14,342 [Thread-1841] INFO  ScriptRunner     -     [junit]      at java.lang.Class.getConstructor0(Class.java:2678)

2008-02-21 13:36:14,342 [Thread-1841] INFO  ScriptRunner     -     [junit]      at java.lang.Class.getConstructor(Class.java:1629)

2008-02-21 13:36:14,343 [Thread-1841] INFO  ScriptRunner     -     [junit]
2008-02-21 13:36:14,343 [Thread-1841] INFO  ScriptRunner     -     [junit]
2008-02-21 13:36:14,344 [Thread-1841] INFO  ScriptRunner     -     [junit] Testcase: initializationError1(test.dit.ops.caps.warehouse.payment.subscriber.TestMessageExceptions$2):      Caused an ERROR

2008-02-21 13:36:14,344 [Thread-1841] INFO  ScriptRunner     -     [junit] No runnable methods
2008-02-21 13:36:14,345 [Thread-1841] INFO  ScriptRunner     -     [junit] java.lang.Exception: No runnable methods
2008-02-21 13:36:14,346 [Thread-1841] INFO  ScriptRunner     -     [junit]      at java.lang.reflect.Constructor.newInstance(Constructor.java:494)

2008-02-21 13:36:14,346 [Thread-1841] INFO  ScriptRunner     -     [junit]      at java.lang.reflect.Constructor.newInstance(Constructor.java:494)

2008-02-21 13:36:14,347 [Thread-1841] INFO  ScriptRunner     -     [junit]
2008-02-21 13:36:14,347 [Thread-1841] INFO  ScriptRunner     -     [junit]
2008-02-21 13:36:14,704 [Thread-1840] WARN  ScriptRunner     -     [junit] Test test.dit.ops.caps.warehouse.payment.subscriber.TestMessageExceptions$2 FAILED

2008-02-21 13:36:17,374 [Thread-1841] INFO  ScriptRunner     -     [junit] Running test.dit.ops.caps.warehouse.payment.subscriber.TestMessageExceptions$3

2008-02-21 13:36:17,381 [Thread-1841] INFO  ScriptRunner     -     [junit] Testsuite: test.dit.ops.caps.warehouse.payment.subscriber.TestMessageExceptions$3

2008-02-21 13:36:18,249 [Thread-1841] INFO  ScriptRunner     -     [junit] Tests run: 2, Failures: 0, Errors: 2, Time elapsed: 0.874 sec

2008-02-21 13:36:18,252 [Thread-1841] INFO  ScriptRunner     -     [junit] Tests run: 2, Failures: 0, Errors: 2, Time elapsed: 0.874 sec

2008-02-21 13:36:18,252 [Thread-1841] INFO  ScriptRunner     -     [junit]
2008-02-21 13:36:18,253 [Thread-1841] INFO  ScriptRunner     -     [junit] Testcase: initializationError0(test.dit.ops.caps.warehouse.payment.subscriber.TestMessageExceptions$3):      Caused an ERROR

2008-02-21 13:36:18,253 [Thread-1841] INFO  ScriptRunner     -     [junit] Test class should have public zero-argument constructor

2008-02-21 13:36:18,254 [Thread-1841] INFO  ScriptRunner     -     [junit] java.lang.Exception: Test class should have public zero-argument constructor

2008-02-21 13:36:18,254 [Thread-1841] INFO  ScriptRunner     -     [junit]      at java.lang.reflect.Constructor.newInstance(Constructor.java:494)

2008-02-21 13:36:18,255 [Thread-1841] INFO  ScriptRunner     -     [junit]      at java.lang.reflect.Constructor.newInstance(Constructor.java:494)

2008-02-21 13:36:18,256 [Thread-1841] INFO  ScriptRunner     -     [junit] Caused by: java.lang.NoSuchMethodException: test.dit.ops.caps.warehouse.payment.subscriber.TestMessageExceptions$3.<init>()

2008-02-21 13:36:18,256 [Thread-1841] INFO  ScriptRunner     -     [junit]      at java.lang.Class.getConstructor0(Class.java:2678)

2008-02-21 13:36:18,257 [Thread-1841] INFO  ScriptRunner     -     [junit]      at java.lang.Class.getConstructor(Class.java:1629)

2008-02-21 13:36:18,257 [Thread-1841] INFO  ScriptRunner     -     [junit]
2008-02-21 13:36:18,258 [Thread-1841] INFO  ScriptRunner     -     [junit]
2008-02-21 13:36:18,258 [Thread-1841] INFO  ScriptRunner     -     [junit] Testcase: initializationError1(test.dit.ops.caps.warehouse.payment.subscriber.TestMessageExceptions$3):      Caused an ERROR

2008-02-21 13:36:18,259 [Thread-1841] INFO  ScriptRunner     -     [junit] No runnable methods
2008-02-21 13:36:18,259 [Thread-1841] INFO  ScriptRunner     -     [junit] java.lang.Exception: No runnable methods
2008-02-21 13:36:18,260 [Thread-1841] INFO  ScriptRunner     -     [junit]      at java.lang.reflect.Constructor.newInstance(Constructor.java:494)

2008-02-21 13:36:18,261 [Thread-1841] INFO  ScriptRunner     -     [junit]      at java.lang.reflect.Constructor.newInstance(Constructor.java:494)

2008-02-21 13:36:18,261 [Thread-1841] INFO  ScriptRunner     -     [junit]
2008-02-21 13:36:18,261 [Thread-1841] INFO  ScriptRunner     -     [junit]
2008-02-21 13:36:18,649 [Thread-1840] WARN  ScriptRunner     -     [junit] Test test.dit.ops.caps.warehouse.payment.subscriber.TestMessageExceptions$3 FAILED

I'm trying to work out why these exceptions are generated and how to remove them.  Adding a public no arg constructor to my test class, as follows, doesn't get rid of the error.

public TestMessageExceptions() {
                super();
}

However I notice that the Expectations class uses an anonymous inner class as follows:

        public void testIMDE() {
                ...
                context.checking( new Expectations() {
                        {
                                one( mockExceptionService ).persist(with(any(ReportableException.class)));
                        }
                });    
                ...
        }      
       
Could this be the source of these exceptions? The NoSuchMethodException is thrown the same number of times as I have tests, implying it's happening on a per test basis.

Your help is appreciated!

Regards,

Murray
       


==============================================================================
Please access the attached hyperlink for an important electronic communications disclaimer: 

http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html
==============================================================================

©2008 gg3721.com - Jax Systems, LLC, U.S.A.