java - Spring autowiring keeps JMockit mocks around for other tests -


i'm trying unit test class (let's say, "classundertest") , use of particular library class (let's call "helper"). i'm injecting mocked helper classundertest , using expectations check things out.

 public class testuseofhelper {      @autowired classundertest classundertest;      @mocked    helperclass    helper;  [...]      @before      public void setup() throws exception {          deencapsulation.setfield(classundertest, "helper", helper);      }  [...]      @test      public void test() {          new expectations() {{              helper.dosomething(any);          }};           classundertest.usehelper();     } 

so far, good.

in other tests (same package, different file), i'm testing other aspects of classundertest want helper thing.

 public class testotherqualities {      @autowired classundertest classundertest;  [...]      @test      public void test() {         result = classundertest.processsomething();         assertnonnull(result);     } 

those tests work fine well.

the problem comes in when run suite of tests. now, second set fails, apparently because mocked helper still in place!

i assume full suite being executed in same jvm , spring has created 1 classundertest, injects mock it's told, reuses same classundertest object next test. how keep them separate? how can "fresh" objects each separate test file? not getting/googling?

i've tried numerous variations of defining objects within expectations blocks , using @tested/@injected no luck. btw, i'm avoiding mocking helper in other tests because need thing. classundertest autowires bunch of other objects, in turn autowire still others, mocking classundertest references impractical.

any insights, oh knowledgeable stack overflow magic 8 ball? ("try later" not acceptable.)

annotate test class with

@dirtiescontext(classmode = after_class) 

if want reset app context between test classes.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -