Search in sources :

Example 1 with TestCluster

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());
}
Also used : GenericAccessibleObject(org.evosuite.utils.generic.GenericAccessibleObject) InheritanceTree(org.evosuite.setup.InheritanceTree) TestCluster(org.evosuite.setup.TestCluster) TestClusterGenerator(org.evosuite.setup.TestClusterGenerator) FinalPrimitiveField(com.examples.with.different.packagename.clinit.FinalPrimitiveField) Test(org.junit.Test)

Example 2 with TestCluster

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());
}
Also used : GenericAccessibleObject(org.evosuite.utils.generic.GenericAccessibleObject) FinalReferenceField(com.examples.with.different.packagename.clinit.FinalReferenceField) InheritanceTree(org.evosuite.setup.InheritanceTree) TestCluster(org.evosuite.setup.TestCluster) TestClusterGenerator(org.evosuite.setup.TestClusterGenerator) Test(org.junit.Test)

Example 3 with TestCluster

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());
            }
        }
    }
}
Also used : GenericAccessibleObject(org.evosuite.utils.generic.GenericAccessibleObject) TestCluster(org.evosuite.setup.TestCluster) GenericConstructor(org.evosuite.utils.generic.GenericConstructor) GenericMethod(org.evosuite.utils.generic.GenericMethod)

Aggregations

TestCluster (org.evosuite.setup.TestCluster)3 GenericAccessibleObject (org.evosuite.utils.generic.GenericAccessibleObject)3 InheritanceTree (org.evosuite.setup.InheritanceTree)2 TestClusterGenerator (org.evosuite.setup.TestClusterGenerator)2 Test (org.junit.Test)2 FinalPrimitiveField (com.examples.with.different.packagename.clinit.FinalPrimitiveField)1 FinalReferenceField (com.examples.with.different.packagename.clinit.FinalReferenceField)1 GenericConstructor (org.evosuite.utils.generic.GenericConstructor)1 GenericMethod (org.evosuite.utils.generic.GenericMethod)1