Skip to content
Permalink
Browse files

[FIXED JENKINS-6446] Modified the scoring mechanism as follows to avo…

…id the inconsistency in granting marks.

    Passing test
        added: +1
        removed: -1
    Failing test
        added: -1
        removed: +1
    Skipped test (no marks given or reduced)
        added: 0
        removed: 0

Following is the details of how all scenarios are handled.

    Passing Tests
        Passing test added = +1
            [Increases passing count = +1]
        Passing test removed = -1
            [Decreases passing count = -1]
        Passing an already failing test = +2
            [Decreases failing count = +1]
            [Increases passing count = +1]
        Passing an already skipped test = +1
            [Decreases skipped count = 0]
            [Increases passing count = +1]

    Failing tests
        Failing test added = -1
            [Increases failing count = -1]
        Failing test removed = +1
            [Decreases failing count = +1]
        Failing an already passing test = -2
            [Decreases passing count = -1]
            [Increases failing count = -1]
        Failing an already skipped test = -1
            [Decreases skipped count = 0]
            [Increases failing count = -1]

    Skipped tests
        Skipped test added = 0
            [Increases skipped count = 0]
        Skipped test removed = 0
            [Decreases skipped count = 0]
        Skipped an already passing test = -1
            [Decreases passing count = -1]
            [Increases skipped count = 0]
        Skipped an already failing test = +1
            [Decreases failing count = +1]
            [Increases skipped count = 0]
  • Loading branch information...
lkamal committed Oct 20, 2013
1 parent 9309fee commit 081f250e4d42cf5f2e6194f57f6e9d0cbf47d9c2
Showing with 334 additions and 260 deletions.
  1. +1 −0 src/main/java/hudson/plugins/cigame/rules/build/BuildResultRule.java
  2. +24 −0 src/main/java/hudson/plugins/cigame/rules/unittesting/AbstractFailedTestsRule.java
  3. +25 −0 src/main/java/hudson/plugins/cigame/rules/unittesting/AbstractPassedTestsRule.java
  4. +23 −0 src/main/java/hudson/plugins/cigame/rules/unittesting/AbstractSkippedTestsRule.java
  5. +3 −0 src/main/java/hudson/plugins/cigame/rules/unittesting/AbstractUnitTestsRule.java
  6. +43 −0 src/main/java/hudson/plugins/cigame/rules/unittesting/DecreasingFailedTestsRule.java
  7. +43 −0 src/main/java/hudson/plugins/cigame/rules/unittesting/DecreasingPassedTestsRule.java
  8. +43 −0 src/main/java/hudson/plugins/cigame/rules/unittesting/DecreasingSkippedTestsRule.java
  9. +16 −27 src/main/java/hudson/plugins/cigame/rules/unittesting/IncreasingFailedTestsRule.java
  10. +22 −45 src/main/java/hudson/plugins/cigame/rules/unittesting/IncreasingPassedTestsRule.java
  11. +42 −0 src/main/java/hudson/plugins/cigame/rules/unittesting/IncreasingSkippedTestsRule.java
  12. +0 −38 src/main/java/hudson/plugins/cigame/rules/unittesting/RemovedFailedTestsRule.java
  13. +0 −129 src/main/java/hudson/plugins/cigame/rules/unittesting/RemovedPassedTestsRule.java
  14. +15 −4 src/main/java/hudson/plugins/cigame/rules/unittesting/UnitTestingRuleSet.java
  15. +10 −6 src/main/resources/hudson/plugins/cigame/rules/unittesting/Messages.properties
  16. +3 −3 src/test/java/hudson/plugins/cigame/rules/unittesting/IncreasingFailedTestsRuleTest.java
  17. +12 −4 src/test/java/hudson/plugins/cigame/rules/unittesting/IncreasingPassedTestsRuleTest.java
  18. +9 −4 src/test/java/hudson/plugins/cigame/rules/unittesting/MavenMultiModuleUnitTestsTest.java
@@ -13,6 +13,7 @@
private int failurePoints;
private int successPoints;

// TODO you can expose this 1 and -10 values as a configuration
public BuildResultRule() {
this(1, -10);
}
@@ -0,0 +1,24 @@
package hudson.plugins.cigame.rules.unittesting;

import hudson.plugins.cigame.model.RuleResult;
import hudson.tasks.test.AbstractTestResultAction;

/**
* Rule that gives points for increasing or decreasing the number of failed
* tests. This is done by comparing the current with the previous build.
*
* @author <a href="www.digizol.com">Kamal Mettananda</a>
* @since 1.20
*/
public abstract class AbstractFailedTestsRule extends AbstractUnitTestsRule {

protected abstract RuleResult<Integer> evaluate(int failedTestDiff);

@Override
protected RuleResult<Integer> evaluate(AbstractTestResultAction<?> testResult,
AbstractTestResultAction<?> previousTestResult) {

return evaluate(testResult.getFailCount() - previousTestResult.getFailCount());
}

}
@@ -0,0 +1,25 @@
package hudson.plugins.cigame.rules.unittesting;

import hudson.plugins.cigame.model.RuleResult;
import hudson.tasks.test.AbstractTestResultAction;

/**
* Rule that gives points for increasing or decreasing the number of passed
* tests. This is done by comparing the current with the previous build.
*
* @author <a href="www.digizol.com">Kamal Mettananda</a>
* @since 1.20
*/
public abstract class AbstractPassedTestsRule extends AbstractUnitTestsRule {

protected abstract RuleResult<Integer> evaluate(int passedTestDiff);

@Override
protected RuleResult<Integer> evaluate(AbstractTestResultAction<?> testResult,
AbstractTestResultAction<?> previousTestResult) {

return evaluate((testResult.getTotalCount() - testResult.getFailCount() - testResult.getSkipCount())
- (previousTestResult.getTotalCount() - previousTestResult.getFailCount() - previousTestResult.getSkipCount()));
}

}
@@ -0,0 +1,23 @@
package hudson.plugins.cigame.rules.unittesting;

import hudson.plugins.cigame.model.RuleResult;
import hudson.tasks.test.AbstractTestResultAction;

/**
* Rule that gives points for increasing or decreasing the number of skipped
* tests. This is done by comparing the current with the previous build.
*
* @author <a href="www.digizol.com">Kamal Mettananda</a>
* @since 1.20
*/
public abstract class AbstractSkippedTestsRule extends AbstractUnitTestsRule {

protected abstract RuleResult<Integer> evaluate(int skippedTestDiff);

@Override
protected RuleResult<Integer> evaluate(AbstractTestResultAction<?> testResult,
AbstractTestResultAction<?> previousTestResult) {
return evaluate(testResult.getSkipCount() - previousTestResult.getSkipCount());
}

}
@@ -100,6 +100,9 @@ public int getSkipCount() {
prevResult = prevResult != null ? prevResult : Result.ABORTED;
result = result != null ? result : Result.ABORTED;

// if the current action is null, let's assume as a ZERO result
action = action != null ? action : ZERO_RESULT;

if ((prevResult.isBetterThan(Result.FAILURE))
&& (result.isBetterThan(Result.FAILURE))) {
return evaluate(action, prevAction);
@@ -0,0 +1,43 @@
package hudson.plugins.cigame.rules.unittesting;

import hudson.plugins.cigame.model.RuleResult;

/**
* Rule that gives points for decreasing the number of failed tests. By default 1 mark given.
*
* @author <a href="www.digizol.com">Kamal Mettananda</a>
* @since 1.20
*/
public class DecreasingFailedTestsRule extends AbstractFailedTestsRule {

private int pointsForDecreasingOneFailedTest;

public DecreasingFailedTestsRule() {
this(1);
}

public DecreasingFailedTestsRule(int points) {
pointsForDecreasingOneFailedTest = points;
}

public String getName() {
return Messages.UnitTestingRuleSet_DecreasingFailedRule_Name();
}

@Override
protected String getResultDescription(Integer testDiff) {
return Messages.UnitTestingRuleSet_DecreasingFailedRule_Count(testDiff);
}

@Override
protected RuleResult<Integer> evaluate(int failedTestDiff) {
if (failedTestDiff < 0) {
failedTestDiff = -failedTestDiff;
return new RuleResult<Integer>(failedTestDiff * pointsForDecreasingOneFailedTest,
Messages.UnitTestingRuleSet_DecreasingFailedRule_Count(failedTestDiff),
failedTestDiff);
}
return null;
}

}
@@ -0,0 +1,43 @@
package hudson.plugins.cigame.rules.unittesting;

import hudson.plugins.cigame.model.RuleResult;

/**
* Rule that gives points for decreasing the number of passed tests. By default -1 mark given.
*
* @author <a href="www.digizol.com">Kamal Mettananda</a>
* @since 1.20
*/
public class DecreasingPassedTestsRule extends AbstractPassedTestsRule {

private int pointsForDecreasingOnePassingTest;

public DecreasingPassedTestsRule() {
this(-1);
}

public DecreasingPassedTestsRule(int points) {
pointsForDecreasingOnePassingTest = points;
}

public String getName() {
return Messages.UnitTestingRuleSet_DecreasingPassedRule_Name();
}

@Override
protected String getResultDescription(Integer testDiff) {
return Messages.UnitTestingRuleSet_DecreasingPassedRule_Count(testDiff);
}

@Override
protected RuleResult<Integer> evaluate(int passedTestDiff) {
if (passedTestDiff < 0) {
passedTestDiff = -passedTestDiff;
return new RuleResult<Integer>(passedTestDiff * pointsForDecreasingOnePassingTest,
Messages.UnitTestingRuleSet_DecreasingPassedRule_Count(passedTestDiff),
passedTestDiff);
}
return null;
}

}
@@ -0,0 +1,43 @@
package hudson.plugins.cigame.rules.unittesting;

import hudson.plugins.cigame.model.RuleResult;

/**
* Rule that gives points for decreasing the number of skipped tests. By default 0 marks given.
*
* @author <a href="www.digizol.com">Kamal Mettananda</a>
* @since 1.20
*/
public class DecreasingSkippedTestsRule extends AbstractSkippedTestsRule {

private int pointsForDecreasingOneSkippedTest;

public DecreasingSkippedTestsRule() {
this(0);
}

public DecreasingSkippedTestsRule(int points) {
pointsForDecreasingOneSkippedTest = points;
}

public String getName() {
return Messages.UnitTestingRuleSet_DecreasingSkippedRule_Name();
}

@Override
protected String getResultDescription(Integer testDiff) {
return Messages.UnitTestingRuleSet_DecreasingSkippedRule_Count(testDiff);
}

@Override
protected RuleResult<Integer> evaluate(int skippedTestDiff) {
if (skippedTestDiff < 0) {
skippedTestDiff = -skippedTestDiff;
return new RuleResult<Integer>(skippedTestDiff * pointsForDecreasingOneSkippedTest,
Messages.UnitTestingRuleSet_DecreasingSkippedRule_Count(skippedTestDiff),
skippedTestDiff);
}
return null;
}

}
@@ -1,53 +1,42 @@
package hudson.plugins.cigame.rules.unittesting;

import hudson.plugins.cigame.model.RuleResult;
import hudson.tasks.test.AbstractTestResultAction;

/**
* Rule for giving points if a new test is added and fails.
* Rule for giving points if a test fails (new or existing). By default -1 mark given.
*
* @author Unknown
* @author <a href="www.digizol.com">Kamal Mettananda</a>
* @since 1.20
*/
public class IncreasingFailedTestsRule extends AbstractUnitTestsRule {
public class IncreasingFailedTestsRule extends AbstractFailedTestsRule {

private double pointsForEachNewFailure;
private int pointsForIncreasingOneFailedTest;

public IncreasingFailedTestsRule() {
this(-1);
}

public IncreasingFailedTestsRule(int points) {
pointsForEachNewFailure = points;
pointsForIncreasingOneFailedTest = points;
}

public String getName() {
return Messages.UnitTestingRuleSet_IncreasingFailedRule_Name();
}

RuleResult<Integer> evaluate(
int currentFailCount, int previousFailCount) {
int failingTestDiff = currentFailCount - previousFailCount;
@Override
protected String getResultDescription(Integer testDiff) {
return Messages.UnitTestingRuleSet_IncreasingFailedRule_Count(testDiff);
}

@Override
protected RuleResult<Integer> evaluate(int failingTestDiff) {
if (failingTestDiff > 0) {
return new RuleResult<Integer>(failingTestDiff * pointsForEachNewFailure,
return new RuleResult<Integer>(failingTestDiff * pointsForIncreasingOneFailedTest,
Messages.UnitTestingRuleSet_IncreasingFailedRule_Count(failingTestDiff),
failingTestDiff);
}
return null;
}

@Override
@SuppressWarnings("unchecked")
protected RuleResult evaluate(
AbstractTestResultAction testResult,
AbstractTestResultAction previousTestResult) {
if (testResult == null) {
return null;
}

return evaluate(
testResult.getFailCount(), previousTestResult.getFailCount());
}

@Override
protected String getResultDescription(Integer testDiff) {
return Messages.UnitTestingRuleSet_IncreasingFailedRule_Count(testDiff);
}
}
@@ -1,66 +1,43 @@
package hudson.plugins.cigame.rules.unittesting;

import hudson.plugins.cigame.model.RuleResult;
import hudson.tasks.test.AbstractTestResultAction;

/**
* Rule that gives points for increasing the number of passed tests.
* Rule that gives points for increasing the number of passed tests. By default 1 mark given.
*
* @author Unknown
* @author <a href="www.digizol.com">Kamal Mettananda</a>
* @since 1.20
*/
public class IncreasingPassedTestsRule extends AbstractUnitTestsRule {
public class IncreasingPassedTestsRule extends AbstractPassedTestsRule {

private int pointsForEachFixedFailure;
private int pointsForIncreasingOnePassingTest;

public IncreasingPassedTestsRule() {
this(1);
}

public IncreasingPassedTestsRule(int points) {
pointsForEachFixedFailure = points;
pointsForIncreasingOnePassingTest = points;
}

RuleResult<Integer> evaluate(
int currentTotalCount, int currentFailCount, int currentSkipCount,
int previousTotalCount, int previousFailCount, int previousSkipCount) {

int passedTestDiff = (currentTotalCount - currentFailCount - currentSkipCount)
- (previousTotalCount - previousFailCount - previousSkipCount);

// ignore any tests which were just 'unskipped'
if (currentSkipCount < previousSkipCount) {
passedTestDiff = passedTestDiff - (previousSkipCount - currentSkipCount);
}

// passedTestDiff may now be 0 or even negative. Count at least all
// those tests which were fixed
passedTestDiff = Math.max(passedTestDiff, previousFailCount - currentFailCount);

if (passedTestDiff > 0) {
return new RuleResult<Integer>(passedTestDiff * pointsForEachFixedFailure,
Messages.UnitTestingRuleSet_IncreasingPassedRule_Count(passedTestDiff),
passedTestDiff);
}
return null;
public String getName() {
return Messages.UnitTestingRuleSet_IncreasingPassedRule_Name();
}

public String getName() {
return Messages.UnitTestingRuleSet_IncreasingPassedRule_Name();
@Override
protected String getResultDescription(Integer testDiff) {
return Messages.UnitTestingRuleSet_IncreasingPassedRule_Count(testDiff);
}

@Override
protected RuleResult<Integer> evaluate(
AbstractTestResultAction<?> testResult,
AbstractTestResultAction<?> previousTestResult) {
if (testResult == null) {
return null;
}

return evaluate(
testResult.getTotalCount(), testResult.getFailCount(), testResult.getSkipCount(),
previousTestResult.getTotalCount(), previousTestResult.getFailCount(), previousTestResult.getSkipCount());
}
@Override
protected RuleResult<Integer> evaluate(int passedTestDiff) {
if (passedTestDiff > 0) {
return new RuleResult<Integer>(passedTestDiff * pointsForIncreasingOnePassingTest,
Messages.UnitTestingRuleSet_IncreasingPassedRule_Count(passedTestDiff),
passedTestDiff);
}
return null;
}

@Override
protected String getResultDescription(Integer testDiff) {
return Messages.UnitTestingRuleSet_IncreasingPassedRule_Count(testDiff);
}
}

0 comments on commit 081f250

Please sign in to comment.
You can’t perform that action at this time.