use of com.examples.with.different.packagename.FlagExample1 in project evosuite by EvoSuite.
the class TestTestabilityTransformation method testSimpleFlag.
@Test
public void testSimpleFlag() throws ClassNotFoundException, InstantiationException, IllegalAccessException, SecurityException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException {
Properties.TARGET_CLASS = FlagExample1.class.getCanonicalName();
Class<?> originalClass = defaultClassloader.loadClass(FlagExample1.class.getCanonicalName());
Class<?> instrumentedClass = instrumentingClassloader.loadClass(FlagExample1.class.getCanonicalName());
Object originalInstance = originalClass.newInstance();
Object instrumentedInstance = instrumentedClass.newInstance();
Method originalMethod = originalClass.getMethod("testMe", new Class<?>[] { int.class });
Method instrumentedMethod = instrumentedClass.getMethod("testMe", new Class<?>[] { int.class });
boolean originalResult = (Boolean) originalMethod.invoke(originalInstance, 0);
boolean instrumentedResult = ((Integer) instrumentedMethod.invoke(instrumentedInstance, 0)) > 0;
assertEquals(originalResult, instrumentedResult);
}
use of com.examples.with.different.packagename.FlagExample1 in project evosuite by EvoSuite.
the class TestTestSuiteMinimizer method minimizeSuiteHalfCoverageWithTwoFitnessFunctions.
@Test
public void minimizeSuiteHalfCoverageWithTwoFitnessFunctions() throws ClassNotFoundException, ConstructionFailedException, NoSuchMethodException, SecurityException {
Properties.TARGET_CLASS = FlagExample1.class.getCanonicalName();
Class<?> sut = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(Properties.TARGET_CLASS);
GenericClass clazz = new GenericClass(sut);
DefaultTestCase test = new DefaultTestCase();
GenericConstructor gc = new GenericConstructor(clazz.getRawClass().getConstructors()[0], clazz);
TestFactory testFactory = TestFactory.getInstance();
testFactory.addConstructor(test, gc, 0, 0);
List<VariableReference> parameters = new ArrayList<VariableReference>();
for (int i = 0; i < 10; i++) {
IntPrimitiveStatement ips = new IntPrimitiveStatement(test, 28234 + i);
VariableReference vr = test.addStatement(ips, i + 1);
}
ConstructorStatement ct = new ConstructorStatement(test, gc, parameters);
Method m = clazz.getRawClass().getMethod("testMe", new Class<?>[] { int.class });
GenericMethod method = new GenericMethod(m, sut);
testFactory.addMethod(test, method, 11, 0);
assertEquals(12, test.size());
TestSuiteChromosome tsc = new TestSuiteChromosome();
tsc.addTest(test);
TestSuiteFitnessFunction branch = new BranchCoverageSuiteFitness();
double previous_branch_fitness = branch.getFitness(tsc);
tsc.setFitness(branch, previous_branch_fitness);
assertEquals(previous_branch_fitness, 2.0, 0.0);
TestSuiteFitnessFunction defuse = new DefUseCoverageSuiteFitness();
double previous_defuse_fitness = defuse.getFitness(tsc);
tsc.setFitness(defuse, previous_defuse_fitness);
assertEquals(previous_defuse_fitness, 0.0, 0.0);
List<TestFitnessFactory<? extends TestFitnessFunction>> factories = new ArrayList<TestFitnessFactory<? extends TestFitnessFunction>>();
factories.add(new BranchCoverageFactory());
factories.add(new DefUseCoverageFactory());
TestSuiteMinimizer minimizer = new TestSuiteMinimizer(factories);
minimizer.minimize(tsc, false);
assertEquals(1, tsc.getTests().size());
assertEquals(3, tsc.getTests().get(0).size());
// assertTrue(tsc.getTests().get(0).toCode().equals("FlagExample1 flagExample1_0 = new FlagExample1();\nint int0 = 28234;\nflagExample1_0.testMe(int0);\n"));
double branch_fitness = branch.getFitness(tsc);
assertEquals(previous_branch_fitness, branch_fitness, 0.0);
double defuse_fitness = defuse.getFitness(tsc);
assertEquals(previous_defuse_fitness, defuse_fitness, 0.0);
}
use of com.examples.with.different.packagename.FlagExample1 in project evosuite by EvoSuite.
the class TestTestSuiteMinimizer method minimizeSuiteFullCoverageWithTwoFitnessFunctionsMinimizeTestsEnabled.
@Test
public void minimizeSuiteFullCoverageWithTwoFitnessFunctionsMinimizeTestsEnabled() throws ClassNotFoundException, NoSuchFieldException, SecurityException, ConstructionFailedException, NoSuchMethodException {
Properties.TARGET_CLASS = FlagExample1.class.getCanonicalName();
Class<?> sut = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(Properties.TARGET_CLASS);
GenericClass clazz = new GenericClass(sut);
DefaultTestCase test = new DefaultTestCase();
GenericConstructor gc = new GenericConstructor(clazz.getRawClass().getConstructors()[0], clazz);
TestFactory testFactory = TestFactory.getInstance();
testFactory.addConstructor(test, gc, 0, 0);
List<VariableReference> parameters = new ArrayList<VariableReference>();
for (int i = 0; i < 10; i++) {
IntPrimitiveStatement ips = new IntPrimitiveStatement(test, 28234 + i);
VariableReference vr = test.addStatement(ips, i + 1);
}
ConstructorStatement ct = new ConstructorStatement(test, gc, parameters);
Method m = clazz.getRawClass().getMethod("testMe", new Class<?>[] { int.class });
GenericMethod method = new GenericMethod(m, sut);
testFactory.addMethod(test, method, 11, 0);
parameters = new ArrayList<VariableReference>();
for (int i = 12; i < 15; i++) {
IntPrimitiveStatement ips = new IntPrimitiveStatement(test, i);
VariableReference vr = test.addStatement(ips, i);
}
ct = new ConstructorStatement(test, gc, parameters);
testFactory.addMethod(test, method, 15, 0);
assertEquals(16, test.size());
TestSuiteChromosome tsc = new TestSuiteChromosome();
tsc.addTest(test);
TestSuiteFitnessFunction branch = new BranchCoverageSuiteFitness();
double previous_branch_fitness = branch.getFitness(tsc);
tsc.setFitness(branch, previous_branch_fitness);
assertEquals(previous_branch_fitness, 0.0, 0.0);
TestSuiteFitnessFunction defuse = new DefUseCoverageSuiteFitness();
double previous_defuse_fitness = defuse.getFitness(tsc);
tsc.setFitness(defuse, previous_defuse_fitness);
assertEquals(previous_defuse_fitness, 0.0, 0.0);
List<TestFitnessFactory<? extends TestFitnessFunction>> factories = new ArrayList<TestFitnessFactory<? extends TestFitnessFunction>>();
factories.add(new BranchCoverageFactory());
factories.add(new DefUseCoverageFactory());
TestSuiteMinimizer minimizer = new TestSuiteMinimizer(factories);
minimizer.minimize(tsc, true);
assertEquals(2, tsc.getTests().size());
assertEquals(3, tsc.getTests().get(0).size());
assertEquals(3, tsc.getTests().get(1).size());
// assertTrue(tsc.getTests().get(0).toCode().equals("FlagExample1 flagExample1_0 = new FlagExample1();\nint int0 = 28234;\nflagExample1_0.testMe(int0);\n"));
// assertTrue(tsc.getTests().get(1).toCode().equals("FlagExample1 flagExample1_0 = new FlagExample1();\nint int0 = 28241;\nflagExample1_0.testMe(int0);\n"));
double branch_fitness = branch.getFitness(tsc);
assertEquals(previous_branch_fitness, branch_fitness, 0.0);
double defuse_fitness = defuse.getFitness(tsc);
assertEquals(previous_defuse_fitness, defuse_fitness, 0.0);
}
use of com.examples.with.different.packagename.FlagExample1 in project evosuite by EvoSuite.
the class TestTestSuiteMinimizer method minimizeSuiteHalfCoverage.
@Test
public void minimizeSuiteHalfCoverage() throws ClassNotFoundException, NoSuchFieldException, SecurityException, ConstructionFailedException, NoSuchMethodException {
Properties.TARGET_CLASS = FlagExample1.class.getCanonicalName();
Class<?> sut = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(Properties.TARGET_CLASS);
GenericClass clazz = new GenericClass(sut);
DefaultTestCase test = new DefaultTestCase();
GenericConstructor gc = new GenericConstructor(clazz.getRawClass().getConstructors()[0], clazz);
TestFactory testFactory = TestFactory.getInstance();
testFactory.addConstructor(test, gc, 0, 0);
List<VariableReference> parameters = new ArrayList<VariableReference>();
for (int i = 0; i < 10; i++) {
IntPrimitiveStatement ips = new IntPrimitiveStatement(test, 28234 + i);
VariableReference vr = test.addStatement(ips, i + 1);
}
ConstructorStatement ct = new ConstructorStatement(test, gc, parameters);
Method m = clazz.getRawClass().getMethod("testMe", new Class<?>[] { int.class });
GenericMethod method = new GenericMethod(m, sut);
testFactory.addMethod(test, method, 11, 0);
assertEquals(12, test.size());
TestSuiteChromosome tsc = new TestSuiteChromosome();
tsc.addTest(test);
TestSuiteFitnessFunction ff = new BranchCoverageSuiteFitness();
double previous_fitness = ff.getFitness(tsc);
tsc.setFitness(ff, previous_fitness);
assertEquals(previous_fitness, 2.0, 0.0);
TestSuiteMinimizer minimizer = new TestSuiteMinimizer(new BranchCoverageFactory());
minimizer.minimize(tsc, false);
assertEquals(1, tsc.getTests().size());
assertEquals(3, tsc.getTests().get(0).size());
// assertTrue(tsc.getTests().get(0).toCode().equals("FlagExample1 flagExample1_0 = new FlagExample1();\nint int0 = 28234;\nflagExample1_0.testMe(int0);\n"));
double fitness = ff.getFitness(tsc);
assertEquals(previous_fitness, fitness, 0.0);
}
use of com.examples.with.different.packagename.FlagExample1 in project evosuite by EvoSuite.
the class TestTestSuiteMinimizer method minimizeSuiteFullCoverage.
@Test
public void minimizeSuiteFullCoverage() throws ClassNotFoundException, NoSuchFieldException, SecurityException, ConstructionFailedException, NoSuchMethodException {
Properties.TARGET_CLASS = FlagExample1.class.getCanonicalName();
Class<?> sut = TestGenerationContext.getInstance().getClassLoaderForSUT().loadClass(Properties.TARGET_CLASS);
GenericClass clazz = new GenericClass(sut);
DefaultTestCase test = new DefaultTestCase();
GenericConstructor gc = new GenericConstructor(clazz.getRawClass().getConstructors()[0], clazz);
TestFactory testFactory = TestFactory.getInstance();
testFactory.addConstructor(test, gc, 0, 0);
List<VariableReference> parameters = new ArrayList<VariableReference>();
for (int i = 0; i < 10; i++) {
IntPrimitiveStatement ips = new IntPrimitiveStatement(test, 28234 + i);
VariableReference vr = test.addStatement(ips, i + 1);
}
ConstructorStatement ct = new ConstructorStatement(test, gc, parameters);
Method m = clazz.getRawClass().getMethod("testMe", new Class<?>[] { int.class });
GenericMethod method = new GenericMethod(m, sut);
testFactory.addMethod(test, method, 11, 0);
parameters = new ArrayList<VariableReference>();
for (int i = 12; i < 15; i++) {
IntPrimitiveStatement ips = new IntPrimitiveStatement(test, i);
VariableReference vr = test.addStatement(ips, i);
}
ct = new ConstructorStatement(test, gc, parameters);
testFactory.addMethod(test, method, 15, 0);
assertEquals(16, test.size());
TestSuiteChromosome tsc = new TestSuiteChromosome();
tsc.addTest(test);
TestSuiteFitnessFunction ff = new BranchCoverageSuiteFitness();
double previous_fitness = ff.getFitness(tsc);
tsc.setFitness(ff, previous_fitness);
assertEquals(previous_fitness, 0.0, 0.0);
TestSuiteMinimizer minimizer = new TestSuiteMinimizer(new BranchCoverageFactory());
minimizer.minimize(tsc, false);
assertEquals(1, tsc.getTests().size());
assertEquals(5, tsc.getTests().get(0).size());
// assertTrue(tsc.getTests().get(0).toCode().equals("FlagExample1 flagExample1_0 = new FlagExample1();\nint int0 = 28234;\nint int1 = 28241;\nflagExample1_0.testMe(int1);\nflagExample1_0.testMe(int0);\n"));
double fitness = ff.getFitness(tsc);
assertEquals(previous_fitness, fitness, 0.0);
}
Aggregations