Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Continuous integration: ensure new commits are covered with tests

I'm working on a project that has a lot of legacy code that is not covered with tests.

Is there any way that I could set up the integration server to check that all new commits have a minimum amount of tests (say, coverage is >70%)?

Essentially, I see two options:

  1. Somehow set up the CI server to fail the build when the committed changes are not covered with unit tests. This will ensure that every piece of new code will have tests and that tests for the legacy code will increase with each change.
  2. Set a coverage threshold for the whole project and fail the build if the coverage percentage decreases after a commit. The problem with this is that if I delete a class containing 100 instructions and add a new class with 50 instructions the coverage percentage will go up without me writing any tests.

I like option 1 more because it forces changes in legacy code to be unit tested. This should increase the overall test coverage.

Right now we're using Jenkins as our CI server and JaCoCo for test coverage. Maven is used for building the project and SVN is our main source control.

like image 256
Denis Rosca Avatar asked Apr 03 '13 18:04

Denis Rosca


1 Answers

I know you can configure Jenkins to verify that there is at least one test file as part of the commit. That would not assure good test coverage, but at least you would know there was some kind of test related changes.

like image 84
Mike Rylander Avatar answered Sep 28 '22 21:09

Mike Rylander