-
Notifications
You must be signed in to change notification settings - Fork 349
/
DefaultTestPrioritiser.java
52 lines (42 loc) · 1.66 KB
/
DefaultTestPrioritiser.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package org.pitest.mutationtest.build;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;
import org.pitest.classinfo.ClassName;
import org.pitest.coverage.BlockLocation;
import org.pitest.coverage.CoverageDatabase;
import org.pitest.coverage.TestInfo;
import org.pitest.mutationtest.engine.MutationDetails;
/**
* Assigns tests based on line coverage and order them by execution speed with a
* weighting towards tests whose names imply they are intended to test the
* mutated class
*
* @author henry
*
*/
public class DefaultTestPrioritiser implements TestPrioritiser {
private static final int TIME_WEIGHTING_FOR_DIRECT_UNIT_TESTS = 1000;
private final CoverageDatabase coverage;
public DefaultTestPrioritiser(CoverageDatabase coverage) {
this.coverage = coverage;
}
@Override
public List<TestInfo> assignTests(MutationDetails mutation) {
return prioritizeTests(mutation.getClassName(), pickTests(mutation));
}
private Collection<TestInfo> pickTests(MutationDetails mutation) {
return mutation.getBlocks().stream()
.map(block -> new BlockLocation(mutation.getId().getLocation(), block))
.flatMap(loc -> this.coverage.getTestsForBlockLocation(loc).stream())
.collect(Collectors.toCollection(() -> new HashSet<>()));
}
private List<TestInfo> prioritizeTests(ClassName clazz,
Collection<TestInfo> testsForMutant) {
final List<TestInfo> sortedTis = new ArrayList<>(testsForMutant);
sortedTis.sort(new TestInfoPriorisationComparator(clazz, TIME_WEIGHTING_FOR_DIRECT_UNIT_TESTS));
return sortedTis;
}
}