Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Junit test and expect an exception whilst maintaining code coverage

I am trying to write some JUnits for my application, I believe I have got around 80% code coverage, but when i run the tests my report looks as follows;

code coverage

This is giving me a code coverage result of 52% which is not idea.

Is there an alternative way to write the methods in which an exception is expected so as to maintain my coverage score?

Thanks

like image 687
Biscuit128 Avatar asked Dec 30 '25 08:12

Biscuit128


1 Answers

Don't worry about code coverage of Tests only the code coverage of the source code (not test code).

If you are using emma or jaCoCo, you can use filters to only instrument or report the results of specific classes or directories.

This is much easier to do if you have separate folders for src and test

like image 166
dkatzel Avatar answered Jan 01 '26 22:01

dkatzel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!