Java Mailing List Archive

http://www.gg3721.com/

Home » user.jmock »

[jmock-user] Re: Peculiar expectation error

Sam

2009-11-30

Replies: Find Java Web Hosting

Author LoginPost Reply
Steve,

We're using TestNG here and perhaps my lack of familiarity with it is causing
some issues. However if you could shed some light on the following issue I think
that might go some way towards solving my other issue. I've been receiving the
following error:

java.lang.IllegalArgumentException: a mock with name "object name" already exists

As a work around I've been putting my test fixture in a method called setUp
which was annotated with @BeforeClass. I thought @BeforeMethod annotation would
be more appropriate but that didn't prevent the above error. But given that a
new context object should be created for each test in a test class, I should not
receive the above message, correct?

I'm using the following code to set up the each unit test class (yes, I'm
mocking concrete classes) :

private Mockery context = new Mockery() {{
    setImposteriser(ClassImposteriser.INSTANCE);
  }};


Again, my understanding is that if I have N tests in a class, each test should
receive its own context object. If that is correct then I should only receive
the above error if within the same test I create two or more mock objects with
the same identifier?

Thanks for your help.
Sam



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email


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