Search in sources :

Example 1 with CBranchExample

use of com.examples.with.different.packagename.cbranch.CBranchExample in project evosuite by EvoSuite.

the class CBranchFitnessArchiveSystemTest method test.

@Test
public void test() throws NoSuchMethodException, SecurityException, ClassNotFoundException {
    Properties.TARGET_CLASS = CBranchExample.class.getCanonicalName();
    Properties.CRITERION = new Criterion[] { Criterion.CBRANCH };
    Properties.TEST_ARCHIVE = true;
    InstrumentingClassLoader classLoader = TestGenerationContext.getInstance().getClassLoaderForSUT();
    Class<CBranchExample> sut = (Class<CBranchExample>) classLoader.loadClass(Properties.TARGET_CLASS);
    List<String> classpath = new ArrayList<>();
    String cp = System.getProperty("user.dir") + "/target/test-classes";
    classpath.add(cp);
    ClassPathHandler.getInstance().addElementToTargetProjectClassPath(cp);
    DependencyAnalysis.analyzeClass(Properties.TARGET_CLASS, classpath);
    Constructor<CBranchExample> ctor = sut.getConstructor();
    Method method = sut.getMethod("Subject", String.class, String.class);
    TestSuiteChromosome suiteChromosome = new TestSuiteChromosome();
    TestCaseBuilder builder = new TestCaseBuilder();
    VariableReference fileSuffix1 = builder.appendConstructor(ctor);
    VariableReference string0 = builder.appendStringPrimitive("MY}6.);:<<TtF");
    VariableReference string1 = builder.appendStringPrimitive("bin");
    builder.appendMethod(fileSuffix1, method, string0, string1);
    DefaultTestCase defaultTestCase = builder.getDefaultTestCase();
    suiteChromosome.addTest(defaultTestCase);
    CBranchSuiteFitness fitness = new CBranchSuiteFitness();
    double fitnessValue = fitness.getFitness(suiteChromosome);
    // removes covered goals due to ARCHIVE
    fitness.updateCoveredGoals();
    double fitnessValue2 = fitness.getFitness(suiteChromosome);
    assertTrue(fitnessValue2 <= fitnessValue);
}
Also used : TestCaseBuilder(org.evosuite.symbolic.TestCaseBuilder) VariableReference(org.evosuite.testcase.variable.VariableReference) CBranchSuiteFitness(org.evosuite.coverage.cbranch.CBranchSuiteFitness) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) InstrumentingClassLoader(org.evosuite.instrumentation.InstrumentingClassLoader) CBranchExample(com.examples.with.different.packagename.cbranch.CBranchExample) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) Test(org.junit.Test)

Aggregations

CBranchExample (com.examples.with.different.packagename.cbranch.CBranchExample)1 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 CBranchSuiteFitness (org.evosuite.coverage.cbranch.CBranchSuiteFitness)1 InstrumentingClassLoader (org.evosuite.instrumentation.InstrumentingClassLoader)1 TestCaseBuilder (org.evosuite.symbolic.TestCaseBuilder)1 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)1 VariableReference (org.evosuite.testcase.variable.VariableReference)1 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)1 Test (org.junit.Test)1