-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
1,449 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
botsing-commons/src/test/java/eu/stamp/botsing/commons/PostProcessUtilityTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package eu.stamp.botsing.commons; | ||
|
||
import org.evosuite.Properties; | ||
import org.evosuite.coverage.TestFitnessFactory; | ||
import org.evosuite.result.TestGenerationResult; | ||
import org.evosuite.setup.TestCluster; | ||
import org.evosuite.testcase.TestChromosome; | ||
import org.evosuite.testcase.TestFitnessFunction; | ||
import org.evosuite.testcase.factories.AllMethodsTestChromosomeFactory; | ||
import org.evosuite.testsuite.TestSuiteChromosome; | ||
import org.evosuite.utils.generic.GenericClass; | ||
import org.evosuite.utils.generic.GenericMethod; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.ArrayList; | ||
|
||
import static eu.stamp.botsing.commons.PostProcessUtility.writeJUnitFailingTests; | ||
import static eu.stamp.botsing.commons.PostProcessUtility.writeJUnitTestsAndCreateResult; | ||
|
||
|
||
public class PostProcessUtilityTest { | ||
|
||
private TestSuiteChromosome testSuite; | ||
|
||
@Before | ||
public void generateTestSuite() throws NoSuchMethodException { | ||
Object obj = new String(); | ||
GenericClass gc = Mockito.mock(GenericClass.class); | ||
Mockito.when(gc.hasWildcardOrTypeVariables()).thenReturn(false); | ||
Method m = obj.getClass().getMethod("equals", Object.class); | ||
GenericMethod call = Mockito.mock(GenericMethod.class,Mockito.RETURNS_DEEP_STUBS); | ||
Mockito.doReturn(obj.getClass()).when(call).getDeclaringClass(); | ||
Mockito.when(call.getName()).thenReturn("equals"); | ||
Mockito.when(call.getOwnerClass()).thenReturn(gc); | ||
Mockito.when(call.isMethod()).thenReturn(true); | ||
Mockito.when(call.getOwnerType()).thenReturn(String.class); | ||
Mockito.when(call.getMethod()).thenReturn(m); | ||
Mockito.when(call.getParameterTypes()).thenReturn(m.getParameterTypes()); | ||
Mockito.when(call.getReturnType()).thenReturn(Boolean.TYPE); | ||
Mockito.when(call.isPublic()).thenReturn(true); | ||
Mockito.doReturn(boolean.class).when(call).getRawGeneratedType(); | ||
|
||
|
||
Mockito.when(call.copy()).thenReturn(call); | ||
TestCluster.getInstance().addTestCall(call); | ||
|
||
AllMethodsTestChromosomeFactory testChromosomeFactory = new AllMethodsTestChromosomeFactory(); | ||
TestChromosome test =testChromosomeFactory.getChromosome(); | ||
testSuite = new TestSuiteChromosome(); | ||
testSuite.addTest(test); | ||
} | ||
|
||
@Test | ||
public void testWithoutSearchObjective(){ | ||
TestFitnessFactory testFitnessFactory = Mockito.mock(TestFitnessFactory.class); | ||
ArrayList testFitnessFactoryList = new ArrayList(); | ||
testFitnessFactoryList.add(testFitnessFactory); | ||
PostProcessUtility.postProcessTests(testSuite, testFitnessFactoryList); | ||
// Minimization suppose to remove the test because there is no search objective | ||
assert(testSuite.getTests().size() == 0); | ||
} | ||
|
||
@Test | ||
public void testWithSearchObjective(){ | ||
TestFitnessFunction testFF = Mockito.mock(TestFitnessFunction.class); | ||
Mockito.when(testFF.isCovered(testSuite.getTestChromosome(0))).thenReturn(true); | ||
ArrayList<TestFitnessFunction> coverageGoals = new ArrayList<>(); | ||
coverageGoals.add(testFF); | ||
|
||
Properties.MINIMIZE = false; | ||
TestFitnessFactory testFitnessFactory = Mockito.mock(TestFitnessFactory.class); | ||
Mockito.when(testFitnessFactory.getCoverageGoals()).thenReturn(coverageGoals); | ||
Mockito.when(testFitnessFactory.getCoverageGoals()).thenReturn(coverageGoals); | ||
ArrayList testFitnessFactoryList = new ArrayList(); | ||
testFitnessFactoryList.add(testFitnessFactory); | ||
PostProcessUtility.postProcessTests(testSuite, testFitnessFactoryList); | ||
assert(testSuite.getTests().size() == 1); | ||
} | ||
|
||
@Test | ||
public void testWriteTest(){ | ||
TestGenerationResult writingTest = writeJUnitTestsAndCreateResult(testSuite, Properties.JUNIT_SUFFIX); | ||
String interestingPart = writingTest.getTestSuiteCode().split("public void test0\\(\\) throws Throwable \\{\n")[1]; | ||
interestingPart = interestingPart.replaceAll(" ",""); | ||
assert (interestingPart.startsWith(testSuite.getTests().get(0).toCode())); | ||
|
||
writeJUnitFailingTests(); | ||
|
||
Properties.CHECK_CONTRACTS = true; | ||
writeJUnitFailingTests(); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
botsing-examples/src/test/java/eu/stamp/botsing/coupling/CallerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package eu.stamp.botsing.coupling; | ||
|
||
import org.junit.Test; | ||
|
||
public class CallerTest { | ||
|
||
@Test | ||
public void test0(){ | ||
Caller caller = new Caller(10,20); | ||
caller.firstNumberIsBigger(); | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
botsing-reproduction/src/main/java/eu/stamp/botsing/fitnessfunction/TestLenFF.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package eu.stamp.botsing.fitnessfunction; | ||
|
||
import org.evosuite.testcase.TestChromosome; | ||
import org.evosuite.testcase.TestFitnessFunction; | ||
import org.evosuite.testcase.execution.ExecutionResult; | ||
|
||
public class TestLenFF extends TestFitnessFunction { | ||
@Override | ||
public double getFitness(TestChromosome testChromosome, ExecutionResult executionResult) { | ||
double testLen = testChromosome.getTestCase().size(); | ||
// 1 - Normalize(len) | ||
return (1 - FitnessFunctionHelper.normalize(testLen)); | ||
} | ||
|
||
@Override | ||
public int compareTo(TestFitnessFunction other) { | ||
if (other == null){ | ||
return 1; | ||
} | ||
|
||
if (other instanceof TestLenFF){ | ||
return 0; | ||
} | ||
|
||
return compareClassName(other); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
final int prime = 31; | ||
int result = 1; | ||
return prime * result + (this.getClass().hashCode()); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object obj) { | ||
if (obj == null) { | ||
return false; | ||
} | ||
if (this == obj) { | ||
return true; | ||
} | ||
return getClass() == obj.getClass(); | ||
} | ||
|
||
@Override | ||
public String getTargetClass() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getTargetMethod() { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.