use of org.evosuite.setup.TestCluster in project evosuite by EvoSuite.
the class TestFinalPrimitiveFieldIsNotAddedToCluster method test.
/**
* As RESET_STATIC_FINAL_FIELDS=true removes the <code>final</code> modifier
* of static fields in the target class, the purpose of this test case is to
* check that the TestClusterGenerator indeed does not include these fields.
*
* @throws ClassNotFoundException
* @throws RuntimeException
*/
@Test
public void test() throws ClassNotFoundException, RuntimeException {
Properties.TARGET_CLASS = FinalPrimitiveField.class.getCanonicalName();
Properties.RESET_STATIC_FINAL_FIELDS = true;
ClassPathHandler.getInstance().changeTargetCPtoTheSameAsEvoSuite();
String cp = ClassPathHandler.getInstance().getTargetProjectClasspath();
DependencyAnalysis.analyzeClass(Properties.TARGET_CLASS, Arrays.asList(cp.split(File.pathSeparator)));
InheritanceTree tree = DependencyAnalysis.getInheritanceTree();
TestClusterGenerator gen = new TestClusterGenerator(tree);
assertNotNull(gen);
TestCluster cluster = TestCluster.getInstance();
List<GenericAccessibleObject<?>> testCalls = cluster.getTestCalls();
assertEquals("Unexpected number of TestCalls", 2, testCalls.size());
}
use of org.evosuite.setup.TestCluster in project evosuite by EvoSuite.
the class TestFinalReferenceFieldIsNotAddedToCluster method test.
/**
* As RESET_STATIC_FINAL_FIELDS=true removes the <code>final</code> modifier
* of static fields in the target class, the purpose of this test case is to
* check that the TestClusterGenerator indeed does not include these fields.
*
* @throws ClassNotFoundException
* @throws RuntimeException
*/
@Test
public void test() throws ClassNotFoundException, RuntimeException {
Properties.TARGET_CLASS = FinalReferenceField.class.getCanonicalName();
Properties.RESET_STATIC_FINAL_FIELDS = true;
ClassPathHandler.getInstance().changeTargetCPtoTheSameAsEvoSuite();
String cp = ClassPathHandler.getInstance().getTargetProjectClasspath();
DependencyAnalysis.analyzeClass(Properties.TARGET_CLASS, Arrays.asList(cp.split(File.pathSeparator)));
InheritanceTree tree = DependencyAnalysis.getInheritanceTree();
TestClusterGenerator gen = new TestClusterGenerator(tree);
assertNotNull(gen);
TestCluster cluster = TestCluster.getInstance();
List<GenericAccessibleObject<?>> testCalls = cluster.getTestCalls();
assertEquals("Unexpected number of TestCalls", 2, testCalls.size());
}
use of org.evosuite.setup.TestCluster in project evosuite by EvoSuite.
the class Archive method ignoreMethodCall.
/**
* Informs {@link org.evosuite.setup.TestCluster} that a particular method of a particular class
* has been fully covered, and therefore no need to generate any solution to cover any of its
* targets.
*
* @param className name of the class which contains the method that has been fully covered and
* can be ignored
* @param methodName name of the method that has been fully covered and can be ignored
*/
protected void ignoreMethodCall(String className, String methodName) {
TestCluster cluster = TestCluster.getInstance();
List<GenericAccessibleObject<?>> calls = cluster.getTestCalls();
for (GenericAccessibleObject<?> call : calls) {
if (!call.getDeclaringClass().getName().equals(className)) {
continue;
}
if (call instanceof GenericMethod) {
GenericMethod genericMethod = (GenericMethod) call;
if (!methodName.startsWith(genericMethod.getName())) {
continue;
}
String desc = Type.getMethodDescriptor(genericMethod.getMethod());
if ((genericMethod.getName() + desc).equals(methodName)) {
logger.info("Removing method " + methodName + " from cluster");
cluster.removeTestCall(call);
logger.info("Testcalls left: " + cluster.getNumTestCalls());
}
} else if (call instanceof GenericConstructor) {
GenericConstructor genericConstructor = (GenericConstructor) call;
if (!methodName.startsWith("<init>")) {
continue;
}
String desc = Type.getConstructorDescriptor(genericConstructor.getConstructor());
if (("<init>" + desc).equals(methodName)) {
logger.info("Removing constructor " + methodName + " from cluster");
cluster.removeTestCall(call);
logger.info("Testcalls left: " + cluster.getNumTestCalls());
}
}
}
}
Aggregations