highlight - JaCoCo/EclEmma's Source highlighting function doesn't work when using PowerMock to Mock Constructor -
i used powermock mock constructor.afer launching application,i thought lines shoud green.however,actually lines red.
think mocking constructor results in phenomenon.beacause mocking others,like final classes, ok.how fix problem?
//code: public class people { public string sayhello(){ return "hello"; } } public class family { public string doevent() { people p = new people(); string str = p.sayhello(); system.out.println(str); return str; } } @runwith(powermockrunner.class) @preparefortest(family.class) public class familytest { @test public void test() throws exception { family f = new family(); string str = "hello mock"; people p = powermock.createmock(people.class); powermock.expectnew(people.class).andreturn(p); easymock.expect(p.sayhello()).andreturn(str); powermock.replay(p, people.class); string stractual = f.doevent(); assert.assertequals(str, stractual); powermock.verify(p, people.class); } }
you shouldn't have use @preparefortest
unless mocking static methods inside class.
i believe issue when prepare class test using powermocks runner, funky byte code, eclemma uses line coverage. since not mocking static methods in family class, try removing @preparefortest
.
Comments
Post a Comment