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);
}
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;
}
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);
}
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));
}
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));
}
Aggregations