use of org.kanonizo.framework.objects.TestCase in project kanonizo by kanonizo.
the class AdditionalGreedyAlgorithm method selectTestCase.
@Override
public TestCase selectTestCase(List<TestCase> testCases) {
Collections.sort(testCases, comp);
TestCase next = testCases.get(0);
return next;
}
use of org.kanonizo.framework.objects.TestCase in project kanonizo by kanonizo.
the class ScytheInstrumenter method collectCoverage.
@Override
public void collectCoverage() {
if (SCYTHE_READ) {
if (SCYTHE_FILE.exists()) {
Gson gson = getGson();
try {
Framework.getInstance().getDisplay().notifyTaskStart("Reading Coverage File", true);
ScytheInstrumenter inst = gson.fromJson(new FileReader(SCYTHE_FILE), ScytheInstrumenter.class);
// removing loading window
Framework.getInstance().getDisplay().reportProgress(1, 1);
this.linesCovered = inst.linesCovered;
this.branchesCovered = inst.branchesCovered;
this.testSuite = inst.testSuite;
} catch (FileNotFoundException e) {
e.printStackTrace();
}
} else {
throw new RuntimeException("Scythe Coverage file is missing. Ensure that -Dscythe_output_dir exists and -Dscythe_filename exists within that directory");
}
} else {
try {
Util.suppressOutput();
Framework.getInstance().getDisplay().notifyTaskStart("Running Test Cases", true);
for (TestCase testCase : testSuite.getTestCases()) {
try {
testCase.run();
// debug code to find out where/why failures are occurring. Use
// breakpoints after execution to locate failures
ClassAnalyzer.collectHitCounters(true);
linesCovered.put(testCase, collectLines(testCase));
branchesCovered.put(testCase, collectBranches(testCase));
ClassAnalyzer.resetCoverage();
Framework.getInstance().getDisplay().reportProgress((double) testSuite.getTestCases().indexOf(testCase) + 1, testSuite.getTestCases().size());
} catch (Throwable e) {
e.printStackTrace();
// as much as I hate to catch throwables, it has to be done in this
// instance because not all tests can be guaranteed to run at all
// properly, and sometimes the Java API will
// shutdown without this line
}
}
Util.resumeOutput();
System.out.println("");
logger.info("Finished instrumentation");
} catch (final Exception e) {
// runtime startup exception
reportException(e);
}
if (!SCYTHE_READ && SCYTHE_WRITE) {
if (!SCYTHE_FILE.exists()) {
try {
SCYTHE_FILE.createNewFile();
} catch (IOException e) {
logger.debug("Failed to create coverage file");
}
}
Gson gson = getGson();
String serialised = gson.toJson(this);
try {
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(SCYTHE_FILE, false));
out.write(serialised.getBytes());
out.flush();
} catch (FileNotFoundException e) {
logger.debug("Output file is missing!");
e.printStackTrace();
} catch (IOException e) {
logger.debug("Failed to write output");
e.printStackTrace();
}
}
}
}
use of org.kanonizo.framework.objects.TestCase in project kanonizo by kanonizo.
the class ScytheInstrumenter method collectLines.
private Set<org.kanonizo.framework.objects.Line> collectLines(TestCase testCase) {
Set<org.kanonizo.framework.objects.Line> covered = new HashSet<>();
List<Class<?>> changedClasses = ClassAnalyzer.getChangedClasses();
for (Class<?> cl : changedClasses) {
if (ClassStore.get(cl.getName()) != null) {
ClassUnderTest parent = ClassStore.get(cl.getName());
List<com.scythe.instrumenter.instrumentation.objectrepresentation.Line> lines = ClassAnalyzer.getCoverableLines(cl.getName());
Set<com.scythe.instrumenter.instrumentation.objectrepresentation.Line> linesCovered = lines.stream().filter(line -> line.getHits() > 0).collect(Collectors.toSet());
Set<org.kanonizo.framework.objects.Line> kanLines = linesCovered.stream().map(line -> LineStore.with(parent, line.getLineNumber())).collect(Collectors.toSet());
covered.addAll(kanLines);
}
}
return covered;
}
use of org.kanonizo.framework.objects.TestCase in project kanonizo by kanonizo.
the class ScytheInstrumenter method collectBranches.
private Set<org.kanonizo.framework.objects.Branch> collectBranches(TestCase testCase) {
Set<org.kanonizo.framework.objects.Branch> covered = new HashSet<>();
List<Class<?>> changedClasses = ClassAnalyzer.getChangedClasses();
for (Class<?> cl : changedClasses) {
if (ClassStore.get(cl.getName()) != null) {
ClassUnderTest parent = ClassStore.get(cl.getName());
List<com.scythe.instrumenter.instrumentation.objectrepresentation.Branch> branches = ClassAnalyzer.getCoverableBranches(cl.getName());
Set<com.scythe.instrumenter.instrumentation.objectrepresentation.Branch> branchesCovered = branches.stream().filter(branch -> branch.getHits() > 0).collect(Collectors.toSet());
Set<Branch> kanBranches = branchesCovered.stream().map(branch -> BranchStore.with(parent, branch.getLineNumber(), branch.getGoalId())).collect(Collectors.toSet());
covered.addAll(kanBranches);
}
}
return covered;
}
use of org.kanonizo.framework.objects.TestCase in project kanonizo by kanonizo.
the class Mutation method parseKillMap.
private static void parseKillMap(File kill, TestSuite testSuite) {
CSVParser parser = null;
try {
parser = new CSVParser(new FileReader(kill), CSVFormat.DEFAULT);
for (CSVRecord record : parser.getRecords()) {
if (record.getRecordNumber() == 0) {
continue;
}
int testCase = Integer.parseInt(record.get(0));
int mutantKilled = Integer.parseInt(record.get(1));
TestCase test = testSuite.getOriginalOrdering().get(testCase - 1);
if (!killMap.containsKey(test)) {
killMap.put(test, new ArrayList<Mutant>());
}
killMap.get(test).addAll(getMutants(mutant -> mutant.getMutantId() == mutantKilled));
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
parser.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Aggregations