From 283231f0766e5402d087b86ea3a49e1380d6d2c3 Mon Sep 17 00:00:00 2001 From: Lyuben Todorov Date: Mon, 30 May 2022 14:09:24 +0200 Subject: [PATCH] delete test dir when serializing; attach scaffold code to test generation result --- client/src/main/java/org/evosuite/Properties.java | 2 +- .../org/evosuite/junit/writer/TestSuiteWriter.java | 3 +++ .../result/TestGenerationResultBuilder.java | 7 +++++++ .../evosuite/result/TestGenerationResultImpl.java | 13 +++++++++++++ master/src/main/java/org/evosuite/EvoSuite.java | 13 ++++++++++--- .../main/java/org/evosuite/utils/CompactReport.java | 3 ++- .../java/org/evosuite/utils/CompactTestCase.java | 3 +-- 7 files changed, 37 insertions(+), 7 deletions(-) diff --git a/client/src/main/java/org/evosuite/Properties.java b/client/src/main/java/org/evosuite/Properties.java index bf98d003c7..c7f7915928 100755 --- a/client/src/main/java/org/evosuite/Properties.java +++ b/client/src/main/java/org/evosuite/Properties.java @@ -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") diff --git a/client/src/main/java/org/evosuite/junit/writer/TestSuiteWriter.java b/client/src/main/java/org/evosuite/junit/writer/TestSuiteWriter.java index 56e09707da..4acaf89dad 100755 --- a/client/src/main/java/org/evosuite/junit/writer/TestSuiteWriter.java +++ b/client/src/main/java/org/evosuite/junit/writer/TestSuiteWriter.java @@ -262,6 +262,9 @@ public List writeTestSuite(String name, String directory, List> void fillInformationFromTestData(TestGeneratio result.setUncoveredMutants(uncoveredMutants); result.setExceptionMutants(exceptionMutants); result.setTestSuiteCode(code); + result.setTestScaffoldCode(scaffold); result.setGeneticAlgorithm((GeneticAlgorithm) ga); result.setDSEAlgorithm(dse); for (Map.Entry, Double> e : targetCoverages.entrySet()) { @@ -148,6 +149,8 @@ private > void fillInformationFromTestData(TestGeneratio private String code = ""; + private String scaffold = ""; + private GeneticAlgorithm ga = null; private ExplorationAlgorithmBase dse = null; @@ -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); diff --git a/client/src/main/java/org/evosuite/result/TestGenerationResultImpl.java b/client/src/main/java/org/evosuite/result/TestGenerationResultImpl.java index a31ae81a58..172012f38d 100755 --- a/client/src/main/java/org/evosuite/result/TestGenerationResultImpl.java +++ b/client/src/main/java/org/evosuite/result/TestGenerationResultImpl.java @@ -68,6 +68,8 @@ public class TestGenerationResultImpl> implements TestGe private String testSuiteCode = ""; + private String testScaffoldCode = ""; + private String targetClass = ""; //private String targetCriterion = ""; @@ -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 */ diff --git a/master/src/main/java/org/evosuite/EvoSuite.java b/master/src/main/java/org/evosuite/EvoSuite.java index b1b0c7c1f8..7133ff1135 100755 --- a/master/src/main/java/org/evosuite/EvoSuite.java +++ b/master/src/main/java/org/evosuite/EvoSuite.java @@ -339,14 +339,12 @@ public Object parseCommandLine(String[] args) { } - logger.info("TEST GENERATION START"); List> 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); @@ -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; diff --git a/master/src/main/java/org/evosuite/utils/CompactReport.java b/master/src/main/java/org/evosuite/utils/CompactReport.java index 50f494108b..f6a84d656c 100644 --- a/master/src/main/java/org/evosuite/utils/CompactReport.java +++ b/master/src/main/java/org/evosuite/utils/CompactReport.java @@ -11,19 +11,20 @@ public class CompactReport implements Serializable { public String UUT; public String testSuiteCode; + public String testScaffoldCode; public Set allCoveredLines; public Set allUncoveredLines; public Set allCoveredBranches; public Set allUncoveredBranches; public Set allCoveredMutation; public Set allUncoveredMutation; - public HashMap 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(); diff --git a/master/src/main/java/org/evosuite/utils/CompactTestCase.java b/master/src/main/java/org/evosuite/utils/CompactTestCase.java index 05ae0e763f..a3168e9b74 100644 --- a/master/src/main/java/org/evosuite/utils/CompactTestCase.java +++ b/master/src/main/java/org/evosuite/utils/CompactTestCase.java @@ -30,8 +30,7 @@ public static HashMap buildTestCaseList(TestGenerationR Set 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 coveredLines = testGenerationResult.getCoveredLines(key);