Skip to content

Commit

Permalink
[JENKINS-13458] Added a testcase to verify the new delta computation.
Browse files Browse the repository at this point in the history
This test ensures that the build status is computed from the warnings delta of the current build and the previous build.
  • Loading branch information
uhafner committed Jan 4, 2015
1 parent 8484d1b commit 4a3fd08
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 26 deletions.
Expand Up @@ -6,7 +6,8 @@
import org.jenkinsci.test.acceptance.po.PostBuildStep;

/**
* Abstract job configuration class.
* Job settings for all static analysis plug-ins.
*
* @author Fabian Trampusch
*/
public abstract class AnalysisSettings extends PageAreaImpl implements PostBuildStep {
Expand Down Expand Up @@ -35,15 +36,18 @@ public abstract class AnalysisSettings extends PageAreaImpl implements PostBuild
protected Control newWarningsThresholdFailed = control("canComputeNew/failedNewAll");
protected Control newWarningsThresholdUnstable = control("canComputeNew/unstableNewAll");
protected Control useDeltaValues = control("canComputeNew/useDeltaValues");
protected Control usePreviousBuild = control("canComputeNew/usePreviousBuildAsReference");

/**
* Constructor for the build settings page area.
* @param parent the job currently being configured.
* Creates a new instance of {@link AnalysisSettings}.
*
* @param parent the job currently being configured.
* @param selectorPath the selector path used as prefix.
*/
public AnalysisSettings(Job parent, String selectorPath) {
super(parent, selectorPath);
this.advanced = control("advanced-button");

advanced = control("advanced-button");
}

/**
Expand Down Expand Up @@ -88,6 +92,7 @@ public void setBuildThresholdLimitLow() {

/**
* Build is marked as unstable if at least these warnings are found.
*
* @param threshold number of warnings to set the build to unstable.
*/
public void setBuildUnstableTotalAll(String threshold) {
Expand All @@ -96,8 +101,8 @@ public void setBuildUnstableTotalAll(String threshold) {
}

/**
* Build is marked as unstable if at least these warnings of high
* priority are found.
* Build is marked as unstable if at least these warnings of high priority are found.
*
* @param threshold number of warnings to set the build to unstable.
*/
public void setBuildUnstableTotalHigh(String threshold) {
Expand All @@ -106,8 +111,8 @@ public void setBuildUnstableTotalHigh(String threshold) {
}

/**
* Build is marked as unstable if at least these warnings of normal
* priority are found.
* Build is marked as unstable if at least these warnings of normal priority are found.
*
* @param threshold number of warnings to set the build to unstable.
*/
public void setBuildUnstableTotalNormal(String threshold) {
Expand All @@ -116,8 +121,8 @@ public void setBuildUnstableTotalNormal(String threshold) {
}

/**
* Build is marked as unstable if at least these warnings of low
* priority are found.
* Build is marked as unstable if at least these warnings of low priority are found.
*
* @param threshold number of warnings to set the build to unstable.
*/
public void setBuildUnstableTotalLow(String threshold) {
Expand All @@ -127,6 +132,7 @@ public void setBuildUnstableTotalLow(String threshold) {

/**
* Build is marked as failed if at least these warnings are found.
*
* @param threshold number of warnings to set the build to failed.
*/
public void setBuildFailedTotalAll(String threshold) {
Expand All @@ -135,8 +141,8 @@ public void setBuildFailedTotalAll(String threshold) {
}

/**
* Build is marked as failed if at least these warnings of high
* priority are found.
* Build is marked as failed if at least these warnings of high priority are found.
*
* @param threshold number of warnings to set the build to unstable.
*/
public void setBuildFailedTotalHigh(String threshold) {
Expand All @@ -145,8 +151,8 @@ public void setBuildFailedTotalHigh(String threshold) {
}

/**
* Build is marked as failed if at least these warnings of normal
* priority are found.
* Build is marked as failed if at least these warnings of normal priority are found.
*
* @param threshold number of warnings to set the build to unstable.
*/
public void setBuildFailedTotalNormal(String threshold) {
Expand All @@ -155,8 +161,8 @@ public void setBuildFailedTotalNormal(String threshold) {
}

/**
* Build is marked as failed if at least these warnings of low
* priority are found.
* Build is marked as failed if at least these warnings of low priority are found.
*
* @param threshold number of warnings to set the build to unstable.
*/
public void setBuildFailedTotalLow(String threshold) {
Expand All @@ -166,26 +172,53 @@ public void setBuildFailedTotalLow(String threshold) {

/**
* Build is marked as failed if at least these new warnings are found.
*
* @param threshold number of new warnings to set the build to failed.
*/
public void setNewWarningsThresholdFailed(String threshold) {
public void setNewWarningsThresholdFailed(final String threshold) {
setNewWarningsThresholdFailed(threshold, false);
}

/**
* Build is marked as failed if at least these new warnings are found.
*
* @param threshold number of new warnings to set the build to failed.
* @param usePreviousAsReference determines if the delta computation should use the previous build rather than the
* reference build
*/
public void setNewWarningsThresholdFailed(final String threshold, final boolean usePreviousAsReference) {
ensureAdvancedClicked();
canComputeNew.check(true);
newWarningsThresholdFailed.set(threshold);
usePreviousBuild.check(usePreviousAsReference);
}

/**
* Build is marked as unstable if at least these new warnings are found.
*
* @param threshold number of new warnings to set the build to unstable.
*/
public void setNewWarningsThresholdUnstable(final String threshold) {
setNewWarningsThresholdUnstable(threshold, false);
}

/**
* Build is marked as unstable if at least these new warnings are found.
*
* @param threshold number of new warnings to set the build to unstable.
* @param usePreviousAsReference determines if the delta computation should use the previous build rather than the
* reference build
*/
public void setNewWarningsThresholdUnstable(String threshold) {
public void setNewWarningsThresholdUnstable(final String threshold, final boolean usePreviousAsReference) {
ensureAdvancedClicked();
canComputeNew.check(true);
newWarningsThresholdUnstable.set(threshold);
usePreviousBuild.check(usePreviousAsReference);
}

/**
* Detect new warnings in comparison with the last build.
*
* @param deltaValues compare if true
*/
public void setUseDeltaValues(boolean deltaValues) {
Expand All @@ -196,6 +229,7 @@ public void setUseDeltaValues(boolean deltaValues) {

/**
* Decides if the code analyzer shall run if the build has failed.
*
* @param canRun build if true.
*/
public void setCanRunOnFailed(boolean canRun) {
Expand Down
1 change: 1 addition & 0 deletions src/test/java/plugins/AbstractAnalysisTest.java
Expand Up @@ -256,6 +256,7 @@ private <J extends Job, T extends AnalysisSettings & PostBuildStep> J edit(Strin
//check whether to exchange the copy resource shell step
if (!isAdditionalResource) {
job.removeFirstBuildStep();
elasticSleep(1000); // chrome needs some time
}

//add the new copy resource shell step
Expand Down
35 changes: 27 additions & 8 deletions src/test/java/plugins/CheckStylePluginTest.java
Expand Up @@ -403,25 +403,44 @@ public void configure(CheckstyleFreestyleBuildSettings settings) {
* <li>Build 1: 1 new warning (SUCCESS since no reference build is set)</li>
* <li>Build 2: 2 new warnings (UNSTABLE since threshold is reached)</li>
* <li>Build 3: 1 new warning (UNSTABLE since still one warning is new based on delta with reference build)</li>
* <li>Build 4: 1 new warning (SUCCESS since no reference build is set)</li>
* <li>Build 4: 1 new warning (SUCCESS since there are no warnings)</li>
* </ol>
*/
@Test
public void should_set_build_status_in_build_sequence() {
public void should_set_build_status_in_build_sequence_compare_to_reference_build() {
FreeStyleJob job = setupJob(FILE_WITH_776_WARNINGS, FreeStyleJob.class, CheckstyleFreestyleBuildSettings.class, null);

runBuild(job, 1, Result.SUCCESS, 1);
runBuild(job, 2, Result.UNSTABLE, 2);
runBuild(job, 3, Result.UNSTABLE, 1);
runBuild(job, 4, Result.SUCCESS, 0);
runBuild(job, 1, Result.SUCCESS, 1, false);
runBuild(job, 2, Result.UNSTABLE, 2, false);
runBuild(job, 3, Result.UNSTABLE, 1, false);
runBuild(job, 4, Result.SUCCESS, 0, false);
}

private void runBuild(final FreeStyleJob job, final int number, final Result expectedResult, final int expectedNewWarnings) {
/**
* Creates a sequence of Freestyle builds and checks if the build result is set correctly. New warning threshold is
* set to zero, e.g. a new warning should mark a build as unstable.
* <p/>
* <ol>
* <li>Build 1: 1 new warning (SUCCESS since no reference build is set)</li>
* <li>Build 2: 2 new warnings (UNSTABLE since threshold is reached)</li>
* <li>Build 3: 1 new warning (SUCCESS since all warnings of previous build are fixed)</li>
* </ol>
*/
@Test
public void should_set_build_status_in_build_sequence_compare_to_previous_build() {
FreeStyleJob job = setupJob(FILE_WITH_776_WARNINGS, FreeStyleJob.class, CheckstyleFreestyleBuildSettings.class, null);

runBuild(job, 1, Result.SUCCESS, 1, true);
runBuild(job, 2, Result.UNSTABLE, 2, true);
runBuild(job, 3, Result.SUCCESS, 0, true);
}

private void runBuild(final FreeStyleJob job, final int number, final Result expectedResult, final int expectedNewWarnings, final boolean usePreviousAsReference) {
final String fileName = "checkstyle-result-build" + number + ".xml";
AnalysisConfigurator<CheckstyleFreestyleBuildSettings> buildConfigurator = new AnalysisConfigurator<CheckstyleFreestyleBuildSettings>() {
@Override
public void configure(CheckstyleFreestyleBuildSettings settings) {
settings.setNewWarningsThresholdUnstable("0");
settings.setNewWarningsThresholdUnstable("0", usePreviousAsReference);
settings.pattern.set(fileName);
}
};
Expand Down

0 comments on commit 4a3fd08

Please sign in to comment.