Bläddra i källkod

SONAR-4092 Display number of lines covered by a test

tags/3.5
Julien Lancelot 11 år sedan
förälder
incheckning
86199f0cba

+ 2
- 7
plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/web/tests_viewer.html.erb Visa fil

@@ -59,13 +59,8 @@
test_case[:name] = test.name()
test_case[:status] = test.status()
test_case[:time] = test.durationInMs()
test_case[:covered_lines] = 0
if test.coveredBlocks()
has_covered_lines = true
test.coveredBlocks().each do |covered_block|
test_case[:covered_lines] += covered_block.lines().size
end
end
has_covered_lines = test.hasCoveredBlocks()
test_case[:covered_lines] = test.countCoveredBlocks() if test.hasCoveredBlocks()
if test.status() != 'ok'
test_case[:message] = ''
test_case[:message] = test.message() if test.message()

+ 23
- 0
sonar-core/src/main/java/org/sonar/core/test/DefaultTestCase.java Visa fil

@@ -20,8 +20,12 @@
package org.sonar.core.test;

import com.google.common.base.Preconditions;
import com.google.common.collect.Iterables;
import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Vertex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.sonar.api.test.CoveredTestable;
import org.sonar.api.test.MutableTestCase;
import org.sonar.api.test.TestPlan;
@@ -32,10 +36,13 @@ import org.sonar.core.graph.GraphUtil;
import javax.annotation.Nullable;

import java.util.Collection;
import java.util.List;
import java.util.Set;

public class DefaultTestCase extends BeanVertex implements MutableTestCase {

private static final Logger LOG = LoggerFactory.getLogger(DefaultTestCase.class);

public String type() {
return (String) getProperty("type");
}
@@ -99,7 +106,10 @@ public class DefaultTestCase extends BeanVertex implements MutableTestCase {
}

public void covers(Testable testable, Set<Integer> lines) {
LOG.info("Covers : " + testable.component().key(), " on "+ lines);

Vertex componentVertex = GraphUtil.single(beanGraph().getUnderlyingGraph().getVertices("key", testable.component().key()));
beanGraph().getUnderlyingGraph().addEdge(null, element(), componentVertex, "covers").setProperty("lines", lines);
}

public TestPlan testPlan() {
@@ -107,6 +117,19 @@ public class DefaultTestCase extends BeanVertex implements MutableTestCase {
return beanGraph().wrap(plan, DefaultTestPlan.class);
}

public boolean hasCoveredBlocks(){
return Iterables.size(element().getEdges(Direction.OUT, "covers")) > 0;
}

public int countCoveredBlocks() {
int coveredBlocks = 0;
for (Edge edge : element().getEdges(Direction.OUT, "covers")){
List<String> lines = (List<String>) edge.getProperty("lines");
coveredBlocks = coveredBlocks + lines.size();
}
return coveredBlocks;
}

public Collection<CoveredTestable> coveredBlocks() {
return null;
}

+ 4
- 0
sonar-plugin-api/src/main/java/org/sonar/api/test/MutableTestCase.java Visa fil

@@ -21,6 +21,8 @@ package org.sonar.api.test;

import javax.annotation.Nullable;

import java.util.Set;

public interface MutableTestCase extends TestCase {
MutableTestCase setStatus(String s);

@@ -31,4 +33,6 @@ public interface MutableTestCase extends TestCase {
MutableTestCase setMessage(String s);

MutableTestCase setStackTrace(String s);

void covers(Testable testable, Set<Integer> lines);
}

+ 4
- 0
sonar-plugin-api/src/main/java/org/sonar/api/test/TestCase.java Visa fil

@@ -52,5 +52,9 @@ public interface TestCase {

TestPlan testPlan();

boolean hasCoveredBlocks();

int countCoveredBlocks();

Collection<CoveredTestable> coveredBlocks();
}

Laddar…
Avbryt
Spara