Can I build so that my code never degrades?

I am using hudson CI to manage a direct Java web project, using ant to build.

I would like to point out that the coverage of unit test will never be worse than the previous build, thereby ensuring that any new code is always checked, or at least the coverage is constantly being improved.

Is there a hudson plugin that works this way?

Edit: I'm currently using Emma, ​​but want to switch to another application for coverage.

In addition, as an explanation, I saw thresholds in some Hudson plugins, but this is not quite what I need. For example, what I would like is that if the coverage for Build # 12 was 46%, and someone checked in Build # 13 with 45% coverage, the build would break.

The reason I want to do this is because I have a code base with low testing coverage. We don’t have time to go back and write unit tests retroactively, but I would like to make sure that coverage continues to improve.

UPDATE: Dan pointed to the edge case with my plan, which will definitely be a problem. I think I need to rethink whether this is even a good idea.

+6
java continuous-integration hudson code-coverage
source share
4 answers

Yes. What kind of coating tool do you use?

The Cobertura plugin for Hudson definitely supports this. On the project configuration screen, you can specify threshold values.

Alternatively, you can make Ant fail to build (rather than Hudson) using the cobertura validation task.

EDIT: I'm not sure you can do exactly what you ask for. Even if you could, it could be problematic. For example, suppose you have an average coverage of 75%, but for one class you have coverage of 80%. If you remove this class 80% and all its tests, you will reduce the overall coverage percentage, although none of the other codes will be less tested than before.

+8
source share

This is a kind of hack, but we use it for similar reasons with Findbugs and Checkstyle. You can configure the Ant task to do the following (this can be divided into several tasks, but I combine them for short):

  • Running tests with coverage
  • Perform an analysis of coverage results and get coverage percentage.
  • Read tmp / lastCoverage.txt from the latest build (see step # 5a)
  • Compare the current coverage percentage with the percentage read from lastCoverage.txt
    • If the percentage of DID NOT decreases, write a new percentage above the contents of tmp / lastCoverage.txt
    • If the percentage of DID decreases, save the source file and run the “COVER ERROR” ping (with the Ant echo task).

Note that steps 2 through 5 need not be performed using your own Ant tasks - you can use something like an Ant javac task to run a Java program to do this for you.

Then configure Hudson:

  • In the "Source Control" section, make sure the "Use update" checkbox is selected. This will save the lastCoverage.txt file between assemblies. Note that this can be problematic if you really need things that need to be cleaned between builds.
  • Use the Hudson Text Finder plugin with a regular expression to search for “COAT FAILURES” in the assembly output (make sure “Also search console output” is checked for the plugin). A text search plugin may flag an assembly as unstable.

Obviously, you can replace things like file name / path and console output with anywhere in the context of your assembly.

As I mentioned above, these are pretty hacks, but this is probably one of the few (only?) Ways to get Hudson to compare things in the previous build with the current build.

+3
source share

Another approach would be to use the Sonar plugin for Hudson to maintain coverage trends over time and facilitate assimilation and analysis of results. It will also show coverage in the context of other measures such as checkstyle and pmd

0
source share

Atlassian Clover supports what you want. Look at the clover-check Ant task, in particular the historyDir attribute.

0
source share

All Articles