java - eclemma 1 of 2 branch not covered in Junit -
junit file
public class someclasstest { ... @test public void testsomecontextfailure() throws exception { someclass sc = new someclass(); try { sc.somecontext(null,null); fail("illegalarg expected"); } catch (illegalargumentexception e) {} } @test public void testsomecontextsuccess() throws exception { someclass sc = new someclass(); somecontext in = new somecontext(); in.setname("something"); in.setid("5"); in.setpoints(somepoint.x); try { assertnotnull(sc.somecontext(in,null)); } catch (exception e) {} } }
java file
public class someclasstest { @autowired(required = true) private insureddao insureddao; @override public context somecontext(context c, unused u) throws exception { if(c == null) throw new illegalargumentexception(); insureddao.increasevalue(c); if(c.getpoints() != null) { ...do } return c; }
in java file if(c == null)
highlighted yellow message saying 1 of 2 branches not covered.
throw new illegalargumentexception();
highlighted green
insureddao.increasevalue(c);
everything on , below line red
what missing? (junit test passed on both why isn't covered)?
might bit late, if else comes across this...
first:
have 2 tests of 1 of them fails. test, went through, tested "null" value, eclemma marks if statement "partially covered". -> null check tested, given object, not.
doesn't work way debugger "the test ran until line, failed, did until stage analyzed". eclemma analyzes run (and succeeded) tests.
second:
in class have insureddao.increasevalue(c);
, autowired. in tests have mock object, otherwise fail nullpointerexception
@ line because autowiring not done in junit tests, therefore insureddao
null , method call throw nullpointerexception
.
should have popped in ide, though ;)
Comments
Post a Comment