spockframework / spockframework/spock

Using objenesis prevents running tests from interactive prompt more than once

Open
#428 16 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Module-Core Type-Defect
Dominant language
Java
Stars
3.6k
Forks
483
PR merge metrics
No merged PRs in 30d

Description

Originally reported on Google Code with ID 306

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

Reported by gregap on 2013-03-29 11:45:43

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure by adding objenesis to BuildConfig, entering interactive Grails mode, and issuing repeated test-app calls. Start with org.spockframework.mock.runtime.MockInstantiator.java and the reported SystemServiceSpec setup; done means repeated interactive test runs can create the mock without the ClassCastException.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy, java
Domain
testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.