thenirajpandey / spock

Automatically exported from code.google.com/p/spock
0 stars 0 forks source link

Using objenesis prevents running tests from interactive prompt more than once #306

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem? If possible, provide source code and 
stack trace.

If I include the objenesis dependency in my BuildConfig, my tests run fine when 
executed as 'grails test-app' but fail after the first run if I go into 
interactive mode by typing 'grails' and then issuing 'test-app' calls. This has 
happened in two distinct apps.

The stacktrace is here (I cannot get Grails to give me the entire stacktrace 
either using -Dgrails.full.stacktrace=true or specifying grails.full.stacktrace 
= true in Config.groovy):

org.spockframework.mock.CannotCreateMockException: Cannot create mock for class 
grails.plugins.springsecurity.SpringSecurityServicenull
    at org.spockframework.mock.runtime.MockInstantiator.instantiate(MockInstantiator.java:38)
    at org.spockframework.mock.runtime.ProxyBasedMockFactory$CglibMockFactory.createMock(ProxyBasedMockFactory.java:92)
    at org.spockframework.mock.runtime.ProxyBasedMockFactory.create(ProxyBasedMockFactory.java:49)
    at org.spockframework.mock.runtime.JavaMockFactory.create(JavaMockFactory.java:51)
    at org.spockframework.mock.runtime.CompositeMockFactory.create(CompositeMockFactory.java:44)
    at org.spockframework.lang.SpecInternals.createMock(SpecInternals.java:47)
    at org.spockframework.lang.SpecInternals.createMockImpl(SpecInternals.java:282)
    at org.spockframework.lang.SpecInternals.MockImpl(SpecInternals.java:99)
    at com.xxxx.SystemServiceSpec.setup(SystemServiceSpec.groovy:17)
Caused by: java.lang.ClassCastException
    at java.lang.Class.cast(Class.java:2990)
    at org.spockframework.mock.runtime.MockInstantiator$ObjenesisInstantiator.instantiate(MockInstantiator.java:45)
    at org.spockframework.mock.runtime.MockInstantiator.instantiate(MockInstantiator.java:31)
    ... 8 more

What version of Spock and Groovy are you using?

Spock 0.7, Grails 2.2.0 and 2.1.1

Original issue reported on code.google.com by gre...@gmail.com on 29 Mar 2013 at 11:45

GoogleCodeExporter commented 8 years ago
Issue 300 has been merged into this issue.

Original comment by pnied...@gmail.com on 10 Apr 2013 at 6:16

GoogleCodeExporter commented 8 years ago
I have the same issue but it is not linked to interactive mode.
It's happening when I have one unit spock test that mock a specific service and 
another unit spock integration test that mock the same service.

If I run them together for being tested, it's not working. If I test them 
separatly, it's working.

Original comment by meyskens...@gmail.com on 15 Apr 2013 at 9:35

GoogleCodeExporter commented 8 years ago
I am not in the Grails environment, but I am having the same issue.  Tests with 
mocked resources pass in isolation but, when run as a testing suite, fail with 
the exception: 

org.spockframework.mock.CannotCreateMockException: Cannot create mock for class 
[myClass]null

Is there a specific Mock teardown that needs to be performed to free up those 
resources and allow future mock instances to be created?

I am seeing this with Spock 0.7, Groovy 1.8

Original comment by mrmattri...@gmail.com on 2 May 2013 at 7:19

GoogleCodeExporter commented 8 years ago
Please provide a reproducible example.

Original comment by pnied...@gmail.com on 3 May 2013 at 12:50

GoogleCodeExporter commented 8 years ago
I did in the original report, which was marked as duplicate: 
https://code.google.com/p/spock/issues/detail?id=300

Original comment by diaz.sal...@gmail.com on 3 May 2013 at 5:36

GoogleCodeExporter commented 8 years ago
According to mrmattrichards, he is experiencing this problem outside Grails (or 
does he just mean outside Grails interactive mode?). It would be very helpful 
if I could reproduce this. If the problem only occurs in Grails (and this is my 
current understanding), we will have to find a person knowledgable in Grails 
internals to look into this.

Original comment by pnied...@gmail.com on 3 May 2013 at 6:09

GoogleCodeExporter commented 8 years ago
I'm also experiencing this problem in a grails 2.3.0 app where we use mocks in 
unit tests and also in integration tests.

Original comment by dominicc...@gmail.com on 24 Oct 2013 at 12:52

GoogleCodeExporter commented 8 years ago
When ran with jUnit, tests pass. This problem only occurs when running tests 
with grails. 

Original comment by alvar.lu...@gmail.com on 7 Nov 2013 at 12:54

GoogleCodeExporter commented 8 years ago
The bug doesn't occur when useObjenesis: false

Original comment by alvar.lu...@gmail.com on 7 Nov 2013 at 1:40

GoogleCodeExporter commented 8 years ago
Having the same issue here when running both unit and integration grails tests 
and using mocks in both type of tests with objenesis on the classpath. I can 
confirm that using Mock(useObjenesis: false) when the mocking fails in 
integration tests is a valid workaround.

Original comment by erd...@gmail.com on 28 Jan 2014 at 9:51

GoogleCodeExporter commented 8 years ago
Issue 335 has been merged into this issue.

Original comment by pnied...@gmail.com on 28 Jan 2014 at 9:55

GoogleCodeExporter commented 8 years ago

Original comment by pnied...@gmail.com on 28 Jan 2014 at 9:56

GoogleCodeExporter commented 8 years ago
See Issue 335. Recent Grails versions implement a workaround. Plan to fix for 
1.0.

Original comment by pnied...@gmail.com on 28 Jan 2014 at 9:58

GoogleCodeExporter commented 8 years ago

Original comment by pnied...@gmail.com on 1 Mar 2015 at 11:46