java - spring integration test cleanup for conflicting configuration contexts -
i'm working on application use integration tests intensively since core framework using operates on database.
i have test classes using configuration context class such this:
@runwith(springjunit4classrunner.class) @contextconfiguration(classes = configa.class) public a_test(){ }
the majority of tests using same context above. have on 200+ such tests. needed additional configuration use cases well, this:
@runwith(springjunit4classrunner.class) @contextconfiguration(classes = {configa.class, configb.class}) public b_test(){ }
problem when execute tests maven, or ide runners , loaded cache configa no longer works. spring tries recreate context configa fails because have h2 db configured , spring tries create schemas, tables fails so.
to overcome started use @dirtiescontext on tests. result on 1h build time, reduces developer productivity significantly.
question: possible clear context tests b_test
only? @dirtiescontext(classmode=after_class) doesn't because order of tests not guaranteed(and don't want go way). fails when type of b_test tests last run. same @dirtiescontext(classmode=before_class) visa versa
is possible simulate @dirtiescontext(classmode=after_class) , @dirtiescontext(classmode=before_class) @ same time on bunch of tests?
or there other way solve in general problem?
what tried far:
- junit suites : didn't spring context
- contexthierarchies : didn't case b_type tests dirties context
- test ordering: nobody happy refactoring tests make work magically
how using both @dirtiescontext(classmode=after_class) , @dirtiescontext(methodmode=before_method)?
when that, spring reload context configa.class , configb.class before invoking test methods annotated @dirtiescontext(methodmode=before_method). , then, after tests of b_test finished, spring shutdowns contexts (and next test class springjunit4classrunner load context).
Comments
Post a Comment