0

I am trying to increase the line coverage for my code. I am calling a static method from a non static method. As part of unit test i am trying to cover the test case for below code:

My code:

1 public void myMethod(){
2   something else;    
3   testMethod();
4 }

5 public static void testMethod(){
6    //do something;
7 }

My test code:

8 myService.myMethod();

From above i can see the jacocco coverage missing(Red) for line # 3 but line number 6 shows as covered(green). How can i increase the line coverage in this case by making line #3 covered. Any help/suggestions are appreciated.

ging
  • 219
  • 7
  • 20
  • 1
    You make it execute. There's absolutely no way to tell with code that's simplified past the point of carrying any meaning. – chrylis -cautiouslyoptimistic- Jan 04 '19 at 00:48
  • @chrylis well the code is executed and can see the coverage in green as mention for line #6. But even if the method is called line #3 shows in red(missing from coverage) – ging Jan 04 '19 at 00:56
  • As was already said in https://stackoverflow.com/questions/53897566/jacocoeclemma-plugin-not-showing-line-coverage-even-of-the-execution-goes-thro : please read https://stackoverflow.com/help/mcve and make sure that you provide **complete** example - nobody will be able to guess what "something" means in your example, whereas this is [definitely important](https://stackoverflow.com/a/54034393/244993). – Godin Jan 04 '19 at 07:06

1 Answers1

0

Learn to use a debugger, it will save you so much time and may even extend your life expectancy!

Put a breakpoint on the line of code you are expecting to get coverage. If it gets hit there is something wrong with Jacocco configuration. Else your test is not hitting that code, something is wrong with your test.

Phil Ninan
  • 1,108
  • 1
  • 14
  • 23
  • or breakpoint will be reached and nothing is wrong with configuration - https://stackoverflow.com/a/54034393/244993 ;) – Godin Jan 07 '19 at 22:00