junit - spring Should I use @DirtiesContext on every class -


i have severals junit test

@contextconfiguration(locations = { "file:../business/src/test/resources/application-context-test.xml",         "file:src/main/webapp/web-inf/confa.xml", "classpath:/mvc-dispatcher-servlet-test.xml"}) @webappconfiguration @runwith(springjunit4classrunner.class) public class productcontentcontrollertest { ... } 

inside class tests have run in same context (which case).

but want tests classes independant. assuming default behavior when run test seems run fast.

how works, application context started once every tests classes ?

should add : @dirtiescontext(classmode= classmode.after_class)

on each test class ?

thanks

spring caches application context default when running tests. key spring uses cache made of following:

  • locations (from @contextconfiguration)
  • classes (from @contextconfiguration)
  • contextinitializerclasses (from @contextconfiguration)
  • contextloader (from @contextconfiguration)
  • activeprofiles (from @activeprofiles)
  • resourcebasepath (from @webappconfiguration)

all details of caching can found in documentation.

in experience, there need use @dirtiescontext in order force spring recreate context. haven't come across many situations it's needed - 1 comes mind use of shared cache manager.

you better using on tests absolutely positively need it. execution speed far slow if use @dirtiescontext on every test , won't getting in return.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -