use of org.kanonizo.framework.objects.TestCase in project kanonizo by kanonizo.
the class RandomAlgorithm method generateSolution.
@Override
protected void generateSolution() {
TestSuite suite = problem.clone().getTestSuite();
List<TestCase> testCases = suite.getTestCases();
Collections.shuffle(testCases);
suite.setTestCases(testCases);
setCurrentOptimal(suite);
fitnessEvaluations++;
}
use of org.kanonizo.framework.objects.TestCase in project kanonizo by kanonizo.
the class RandomSearchAlgorithm method generateSolution.
@Override
public void generateSolution() {
FitnessWriter writer = new FitnessWriter(this);
List<TestCase> testCases = problem.getTestSuite().getTestCases();
Display d = Framework.getInstance().getDisplay();
System.out.println("Running Random Search");
while (!shouldFinish()) {
age++;
TestSuite clone = getCurrentOptimal().clone();
List<TestCase> randomOrdering = generateRandomOrder(testCases);
clone.setTestCases(randomOrdering);
fitnessEvaluations++;
if (clone.fitter(getCurrentOptimal()).equals(clone)) {
setCurrentOptimal(clone);
}
if (TRACK_GENERATION_FITNESS) {
writer.addRow(age, getCurrentOptimal().getFitness());
} else {
writer.addRow(age, clone.getFitness());
}
d.reportProgress(Math.min((double) System.currentTimeMillis() - startTime, MAX_EXECUTION_TIME), MAX_EXECUTION_TIME);
}
System.out.println();
writer.write();
}
use of org.kanonizo.framework.objects.TestCase in project kanonizo by kanonizo.
the class Framework method loadClasses.
public void loadClasses() throws ClassNotFoundException {
sut = new SystemUnderTest();
List<File> sourceFiles = findClasses(sourceFolder);
Premain.instrument = true;
for (File file : sourceFiles) {
Class<?> cl = loadClassFromFile(file);
sut.addClass(new ClassUnderTest(cl));
logger.info("Added class " + cl.getName());
}
Premain.instrument = false;
List<File> testFiles = findClasses(testFolder);
for (File file : testFiles) {
Class<?> cl = loadClassFromFile(file);
if (cl != null) {
if (Util.isTestClass(cl)) {
List<Method> testMethods = TestingUtils.getTestMethods(cl);
logger.info("Adding " + testMethods.size() + " test methods from " + cl.getName());
for (Method m : testMethods) {
if (TestingUtils.isParameterizedTest(cl, m)) {
Optional<Method> parameterMethod = Arrays.asList(cl.getMethods()).stream().filter(method -> method.getAnnotation(Parameters.class) != null).findFirst();
if (parameterMethod.isPresent()) {
try {
Iterable<Object[]> parameters = (Iterable<Object[]>) parameterMethod.get().invoke(null, new Object[] {});
for (Object[] inst : parameters) {
ParameterisedTestCase ptc = new ParameterisedTestCase(cl, m, inst);
sut.addTestCase(ptc);
}
} catch (IllegalAccessException e) {
logger.error(e);
} catch (InvocationTargetException e) {
logger.error(e);
}
} else {
logger.error("Trying to create parameterized test case that has no parameter method");
}
} else {
TestCase t = new TestCase(cl, m);
sut.addTestCase(t);
}
}
} else {
sut.addExtraClass(cl);
logger.info("Adding supporting test class " + cl.getName());
}
}
}
ClassUnderTest.resetCount();
logger.info("Finished adding source and test files. Total " + sut.getClassesUnderTest().size() + " classes and " + sut.getTestSuite().size() + " test cases");
}
use of org.kanonizo.framework.objects.TestCase in project kanonizo by kanonizo.
the class KOptimalAlgorithm method selectOptimal.
private List<TestCase> selectOptimal(List<TestCase> testCases) {
List<TestCase> cases = new ArrayList<TestCase>();
double maxFitness = 0.0;
for (int i = 0; i < testCases.size(); i++) {
for (int j = 0; j < testCases.size(); j++) {
if (i > j) {
TestCase tc1 = testCases.get(i);
TestCase tc2 = testCases.get(j);
double fitness = getFitness(tc1, tc2);
if (fitness > maxFitness) {
maxFitness = fitness;
cases.clear();
cases.add(tc1);
cases.add(tc2);
}
}
}
}
return cases;
}
use of org.kanonizo.framework.objects.TestCase in project kanonizo by kanonizo.
the class Schwa method selectTestCase.
@Override
public TestCase selectTestCase(List<TestCase> testCases) {
while (testCasesForActive.size() == 0) {
if (classes.size() > 0) {
// pick next n classes to prioritise tests for, either CLASSES_PER_GROUP or all remaining classes
active.clear();
for (int i = 0; i < Math.min(CLASSES_PER_GROUP, classes.size()); i++) {
active.add(classes.get(i));
}
classes.removeAll(active);
// grab covering test cases
testCasesForActive = getTestsCoveringClasses(testCases, active);
} else {
// if there are no more classes reported by Schwa, just add test cases in the order we found them
testCasesForActive = testCases;
}
if (COMPARATOR != null) {
// secondary objective sort for test cases
testCasesForActive.sort(COMPARATOR);
}
}
TestCase next = testCasesForActive.get(0);
testCasesForActive.remove(next);
return next;
}
Aggregations