java - @InjectMocks @Autowired together issue -
could help me please, code:
@contextconfiguration(locations = { "/applicationcontext.xml" }) @runwith(springjunit4classrunner.class) public class testunit2 { @mock private mongooperations mongotemplate; @injectmocks @autowired private workcirclerepositorymongoimpl workcirclerepository; @autowired private workcircleserviceimpl workcircleserviceimpl; @before public void setup() { .... when(mongotemplate.findone(new query(), person.class)).thenreturn(expectedperson); mockitoannotations.initmocks(this); } @test public void test() { ... workcircleserviceimpl.find()... }
but test failed: np in "... workcircleserviceimpl.find()..." line,
in separate way @injectmocks & @autowired work, not worked.
usually when unit testing, shouldn't initialize spring context. remove autowiring.
usually when integration testing, should utilize real dependencies. remove mocking.
you mixing integration , unit test here.
java spring annotations mockito autowired
No comments:
Post a Comment