Skip to content

Commit

Permalink
delete test dir when serializing; attach scaffold code to test genera…
Browse files Browse the repository at this point in the history
…tion result
  • Loading branch information
Lyuben Todorov committed May 30, 2022
1 parent 032da9a commit 283231f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion client/src/main/java/org/evosuite/Properties.java
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ public enum AssertionStrategy {
@Parameter(key = "show_progress", group = "Output", description = "Show progress bar on console")
public static boolean SHOW_PROGRESS = true;

@Parameter(key = "serialize_result", group = "Output", description = "Serialize result of search to main process")
@Parameter(key = "serialize_result", group = "Output", description = "Serialize result of search to main process. Disables writing to TEST_DIR.")
public static boolean SERIALIZE_RESULT = false;

@Parameter(key = "new_statistics", group = "Output", description = "Use the new statistics backend on the master")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ public List<File> writeTestSuite(String name, String directory, List<ExecutionRe
File file = new File(dir + "/" + scaffoldingName + ".java");
String scaffoldingContent = Scaffolding.getScaffoldingFileContent(name, results,
TestSuiteWriterUtils.hasAnySecurityException(results));

TestGenerationResultBuilder.getInstance().setTestScaffoldCode(scaffoldingContent);

FileIOUtils.writeFile(scaffoldingContent, file);
generated.add(file);
content += scaffoldingContent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ private <T extends Chromosome<T>> void fillInformationFromTestData(TestGeneratio
result.setUncoveredMutants(uncoveredMutants);
result.setExceptionMutants(exceptionMutants);
result.setTestSuiteCode(code);
result.setTestScaffoldCode(scaffold);
result.setGeneticAlgorithm((GeneticAlgorithm<T>) ga);
result.setDSEAlgorithm(dse);
for (Map.Entry<FitnessFunction<?>, Double> e : targetCoverages.entrySet()) {
Expand All @@ -148,6 +149,8 @@ private <T extends Chromosome<T>> void fillInformationFromTestData(TestGeneratio

private String code = "";

private String scaffold = "";

private GeneticAlgorithm<?> ga = null;

private ExplorationAlgorithmBase dse = null;
Expand Down Expand Up @@ -228,6 +231,10 @@ public void setTestSuiteCode(String code) {
this.code = code;
}

public void setTestScaffoldCode(String scaffoldCode) {
this.scaffold = scaffoldCode;
}

public void setGeneticAlgorithm(GeneticAlgorithm<?> ga) {
this.ga = ga;
ga.getBestIndividual().getCoverageValues().forEach(targetCoverages::put);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public class TestGenerationResultImpl<T extends Chromosome<T>> implements TestGe

private String testSuiteCode = "";

private String testScaffoldCode = "";

private String targetClass = "";

//private String targetCriterion = "";
Expand Down Expand Up @@ -194,6 +196,17 @@ public void setTestSuiteCode(String code) {
this.testSuiteCode = code;
}

/**
* Test Suite scaffold code
*/
public String getTestScaffoldCode() {
return testScaffoldCode;
}

public void setTestScaffoldCode(String testScaffoldCode) {
this.testScaffoldCode = testScaffoldCode;
}

/**
* Lines covered by final test suite
*/
Expand Down
13 changes: 10 additions & 3 deletions master/src/main/java/org/evosuite/EvoSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -339,14 +339,12 @@ public Object parseCommandLine(String[] args) {
}


logger.info("TEST GENERATION START");
List<List<TestGenerationResult>> result = TestGeneration.executeTestGeneration(options, javaOpts, line);
logger.info("TEST GENERATION OVER");

if (line.hasOption("serializeResult")) {
String serializePath = line.getOptionValue("serializeResultPath");

logger.info("Serializing test generation report to " + serializePath);
LoggingUtils.getEvoLogger().info("* Serializing test generation report to " + serializePath);

TestGenerationResultImpl testGenerationResult = (TestGenerationResultImpl) result.get(0).get(0);

Expand All @@ -358,6 +356,15 @@ public Object parseCommandLine(String[] args) {
} catch (IOException e) {
logger.error("Error writing file to output stream: " + e);
}

LoggingUtils.getEvoLogger().info("* Removing test dir");

try {
FileUtils.deleteDirectory(new File(Properties.TEST_DIR));
} catch (IOException e) {
logger.error(" Error removing evosuite test dir: " + e);
}

}

return result;
Expand Down
3 changes: 2 additions & 1 deletion master/src/main/java/org/evosuite/utils/CompactReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@
public class CompactReport implements Serializable {
public String UUT;
public String testSuiteCode;
public String testScaffoldCode;
public Set<Integer> allCoveredLines;
public Set<Integer> allUncoveredLines;
public Set<BranchInfo> allCoveredBranches;
public Set<BranchInfo> allUncoveredBranches;
public Set<MutationInfo> allCoveredMutation;
public Set<MutationInfo> allUncoveredMutation;

public HashMap<String, CompactTestCase> testCaseList;

public CompactReport(TestGenerationResultImpl<?> testGenerationResult) {
this.allCoveredLines = testGenerationResult.getCoveredLines();
this.UUT = testGenerationResult.getClassUnderTest();
this.testSuiteCode = testGenerationResult.getTestSuiteCode();
this.testScaffoldCode = testGenerationResult.getTestScaffoldCode();
this.testCaseList = CompactTestCase.buildTestCaseList(testGenerationResult);
this.allUncoveredLines = testGenerationResult.getUncoveredLines();
this.allCoveredBranches = testGenerationResult.getCoveredBranches();
Expand Down
3 changes: 1 addition & 2 deletions master/src/main/java/org/evosuite/utils/CompactTestCase.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ public static HashMap<String, CompactTestCase> buildTestCaseList(TestGenerationR

Set<String> keySet = testGenerationResult.getTestCaseKeySet();

for(String key: keySet){
TestCase testCase = testGenerationResult.getTestCase(key);
for (String key : keySet) {
// see what is exposed by TestCase
String testCode = testGenerationResult.getTestCode(key);
Set<Integer> coveredLines = testGenerationResult.getCoveredLines(key);
Expand Down

0 comments on commit 283231f

Please sign in to comment.