Search in sources :

Example 91 with TestCase

use of org.evosuite.testcase.TestCase in project evosuite by EvoSuite.

the class LocalSearchArraySystemTest method runArrayExample.

private void runArrayExample(int length, double expectedFitness) throws ClassNotFoundException, ConstructionFailedException, NoSuchMethodException, SecurityException {
    TestCase test = getArrayTest(length);
    System.out.println("Test: " + test.toCode());
    TestSuiteChromosome suite = new TestSuiteChromosome();
    BranchCoverageSuiteFitness fitness = new BranchCoverageSuiteFitness();
    BranchCoverageMap.getInstance().searchStarted(null);
    assertEquals(4.0, fitness.getFitness(suite), 0.1F);
    suite.addTest(test);
    // assertEquals(1.0, fitness.getFitness(suite), 0.1F);
    TestSuiteLocalSearch localSearch = TestSuiteLocalSearch.selectTestSuiteLocalSearch();
    LocalSearchObjective<TestSuiteChromosome> localObjective = new DefaultLocalSearchObjective<TestSuiteChromosome>();
    localObjective.addFitnessFunction(fitness);
    localSearch.doSearch(suite, localObjective);
    System.out.println("Fitness: " + fitness.getFitness(suite));
    System.out.println("Test suite: " + suite);
    assertEquals(expectedFitness, fitness.getFitness(suite), 0.1F);
    BranchCoverageMap.getInstance().searchFinished(null);
}
Also used : TestSuiteLocalSearch(org.evosuite.testsuite.localsearch.TestSuiteLocalSearch) DefaultLocalSearchObjective(org.evosuite.ga.localsearch.DefaultLocalSearchObjective) TestCase(org.evosuite.testcase.TestCase) DefaultTestCase(org.evosuite.testcase.DefaultTestCase) BranchCoverageSuiteFitness(org.evosuite.coverage.branch.BranchCoverageSuiteFitness) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome)

Example 92 with TestCase

use of org.evosuite.testcase.TestCase in project evosuite by EvoSuite.

the class JUnitUtils method readTestCase.

/**
 * <p>
 * readTestCase
 * </p>
 *
 * @param failingTest
 *            a {@link java.lang.String} object.
 * @return a {@link org.evosuite.testcase.TestCase} object.
 */
public static TestCase readTestCase(String failingTest) {
    String[] classpath = Properties.CLASSPATH;
    String[] sources = Properties.SOURCEPATH;
    TestCase testCase = new JUnitTestReader(classpath, sources).readJUnitTestCase(failingTest);
    return testCase;
}
Also used : TestCase(org.evosuite.testcase.TestCase)

Example 93 with TestCase

use of org.evosuite.testcase.TestCase in project evosuite by EvoSuite.

the class JUnitTestReaderComplexTest method testReadTestExample.

@Ignore
@Test
public void testReadTestExample() {
    Properties.PROJECT_PREFIX = "org.evosuite.junit";
    JUnitTestReader reader = new JUnitTestReader(null, new String[] { SRCDIR });
    TestCase testCase = reader.readJUnitTestCase(TestExample.class.getName() + "#test01");
    testCase.clone();
    String code = testCase.toCode();
    String result = "int int0 = 0;\n" + // 
    "int int1 = 5;\n" + // 
    "int int2 = 7;\n" + // 
    "int int3 = 10;\n" + // 
    "int int4 = 4;\n" + // 
    "int int5 = 42;\n" + // 
    "int int6 = -5;\n" + // 
    "String string0 = null;\n" + // 
    "String string1 = \"break free!\";\n" + // 
    "int int7 = 38;\n" + // 
    "int int8 = 3;\n" + // 
    "String string2 = \"convert\";\n" + // 
    "String string3 = \"killSelf\";\n" + // 
    "TestExample.MockingBird testExample_MockingBird0 = new TestExample.MockingBird(string3);\n" + // 
    "testExample_MockingBird0.executeCmd(int7);\n";
    Assert.assertEquals(result, code);
}
Also used : TestCase(org.evosuite.testcase.TestCase) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 94 with TestCase

use of org.evosuite.testcase.TestCase in project evosuite by EvoSuite.

the class TestTestCaseExpander method testSomeAssignments.

@Test
public void testSomeAssignments() {
    Properties.PROJECT_PREFIX = "org.evosuite.testsuite";
    JUnitTestReader reader = new JUnitTestReader(null, new String[] { SRCDIR });
    TestCase testCase = reader.readJUnitTestCase(ArrayTestExample1.class.getName() + "#test2");
    testCase.clone();
    String code = testCase.toCode();
    TestCaseExpander expander = new TestCaseExpander();
    TestCase expandedTest = expander.expandTestCase(testCase);
    String expandedCode = expandedTest.toCode();
    Assert.assertEquals(testCase.size() + 14, expandedTest.size());
    Assert.assertFalse(code.equals(expandedCode));
}
Also used : TestCase(org.evosuite.testcase.TestCase) JUnitTestReader(org.evosuite.junit.JUnitTestReader) Test(org.junit.Test)

Example 95 with TestCase

use of org.evosuite.testcase.TestCase in project evosuite by EvoSuite.

the class TestTestCaseExpander method testArrayAssignment.

@Test
public void testArrayAssignment() {
    Properties.PROJECT_PREFIX = "org.evosuite.testsuite";
    JUnitTestReader reader = new JUnitTestReader(null, new String[] { SRCDIR });
    TestCase testCase = reader.readJUnitTestCase(ArrayTestExample1.class.getName() + "#test5");
    testCase.clone();
    String code = testCase.toCode();
    TestCaseExpander expander = new TestCaseExpander();
    TestCase expandedTest = expander.expandTestCase(testCase);
    String expandedCode = expandedTest.toCode();
    Assert.assertEquals("Wrong length of test: " + expandedCode + ", original test: " + code, testCase.size() + 1, expandedTest.size());
    Assert.assertFalse(code.equals(expandedCode));
}
Also used : TestCase(org.evosuite.testcase.TestCase) JUnitTestReader(org.evosuite.junit.JUnitTestReader) Test(org.junit.Test)

Aggregations

TestCase (org.evosuite.testcase.TestCase)192 Test (org.junit.Test)119 DefaultTestCase (org.evosuite.testcase.DefaultTestCase)90 ArrayList (java.util.ArrayList)67 CoverageGoalTestNameGenerationStrategy (org.evosuite.junit.naming.methods.CoverageGoalTestNameGenerationStrategy)47 MethodCoverageTestFitness (org.evosuite.coverage.method.MethodCoverageTestFitness)45 TestSuiteChromosome (org.evosuite.testsuite.TestSuiteChromosome)43 IntPrimitiveStatement (org.evosuite.testcase.statements.numeric.IntPrimitiveStatement)39 VariableReference (org.evosuite.testcase.variable.VariableReference)26 OutputCoverageGoal (org.evosuite.coverage.io.output.OutputCoverageGoal)25 OutputCoverageTestFitness (org.evosuite.coverage.io.output.OutputCoverageTestFitness)25 TestFitnessFunction (org.evosuite.testcase.TestFitnessFunction)24 BranchCoverageSuiteFitness (org.evosuite.coverage.branch.BranchCoverageSuiteFitness)17 TestChromosome (org.evosuite.testcase.TestChromosome)17 InstrumentingClassLoader (org.evosuite.instrumentation.InstrumentingClassLoader)15 Ignore (org.junit.Ignore)15 VariableReferenceImpl (org.evosuite.testcase.variable.VariableReferenceImpl)14 GenericMethod (org.evosuite.utils.generic.GenericMethod)12 ExceptionCoverageTestFitness (org.evosuite.coverage.exception.ExceptionCoverageTestFitness)11 InputCoverageGoal (org.evosuite.coverage.io.input.InputCoverageGoal)10