Best EvoMaster code snippet using org.evomaster.e2etests.utils.WsTestBase.clearGeneratedFiles
Source:WsTestBase.java
...127 */128 String finalSplitType = splitType;129 assertTimeoutPreemptively(Duration.ofMinutes(timeoutMinutes), () -> {130 ClassName className = new ClassName(fullClassName);131 clearGeneratedFiles(outputFolderName, classNames);132 handleFlaky(133 () -> {134 List<String> args = getArgsWithCompilation(iterations, outputFolderName, className, createTests, finalSplitType, "FALSE");135 defaultSeed++;136 lambda.accept(new ArrayList<>(args));137 }138 );139 });140 }141 protected void runTestHandlingFlakyAndCompilation(142 String outputFolderName,143 String fullClassName,144 int iterations,145 Consumer<List<String>> lambda) throws Throwable {146 runTestHandlingFlakyAndCompilation(outputFolderName, fullClassName, null, iterations, true, lambda, 3);147 }148 protected void runTestHandlingFlakyAndCompilation(149 String outputFolderName,150 String fullClassName,151 List<String> terminations,152 int iterations,153 Consumer<List<String>> lambda) throws Throwable {154 runTestHandlingFlakyAndCompilation(outputFolderName, fullClassName, terminations, iterations, true, lambda, 3);155 }156 protected void runTestHandlingFlakyAndCompilation(157 String outputFolderName,158 String fullClassName,159 List<String> terminations,160 int iterations,161 boolean createTests,162 Consumer<List<String>> lambda,163 int timeoutMinutes) throws Throwable {164 runTestHandlingFlaky(outputFolderName, fullClassName, terminations, iterations, createTests,lambda, timeoutMinutes);165 if (terminations == null) terminations = Arrays.asList("");166 //BMR: this is where I should handle multiples???167 if (createTests){168 for (String termination : terminations) {169 assertTimeoutPreemptively(Duration.ofMinutes(2), () -> {170 ClassName className = new ClassName(fullClassName + termination);171 clearCompiledFiles(className);172 //the first one goes through, but for the second generated files appear to not be clean.173 compileRunAndVerifyTests(outputFolderName, className);174 });175 }176 }177 }178 protected void runTestHandlingFlakyAndCompilation(179 String outputFolderName,180 String fullClassName,181 int iterations,182 boolean createTests,183 Consumer<List<String>> lambda,184 int timeoutMinutes) throws Throwable {185 runTestHandlingFlaky(outputFolderName, fullClassName, iterations, createTests,lambda, timeoutMinutes);186 if (createTests){187 assertTimeoutPreemptively(Duration.ofMinutes(2), () -> {188 ClassName className = new ClassName(fullClassName);189 compileRunAndVerifyTests(outputFolderName, className);190 });191 }192 }193 protected void compileRunAndVerifyTests(String outputFolderName, ClassName className){194 ExecutionTracer.setKillSwitch(false); //make sure it is not on195 Class<?> klass = loadClass(className);196 assertNull(klass);197 compile(outputFolderName);198 klass = loadClass(className);199 assertNotNull(klass);200 StringWriter writer = new StringWriter();201 PrintWriter pw = new PrintWriter(writer);202 TestExecutionSummary summary = JUnitTestRunner.runTestsInClass(klass);203 summary.printFailuresTo(pw, 100);204 String failures = writer.toString();205 assertTrue(summary.getContainersFoundCount() > 0);206 assertEquals(0, summary.getContainersFailedCount(), failures);207 assertTrue(summary.getContainersSucceededCount() > 0);208 assertTrue(summary.getTestsFoundCount() > 0);209 assertEquals(0, summary.getTestsFailedCount(), failures);210 assertTrue(summary.getTestsSucceededCount() > 0);211 }212 protected void clearGeneratedFiles(String outputFolderName, List<ClassName> testClassNames){213 File folder = new File(outputFolderPath(outputFolderName));214 try{215 FileUtils.deleteDirectory(folder);216 }catch (Exception e){217 throw new RuntimeException(e);218 }219 for (ClassName testClassName : testClassNames){220 clearCompiledFiles(testClassName);221 }222 }223 protected void clearGeneratedFiles(String outputFolderName, ClassName testClassName){224 List<ClassName> classNames = new ArrayList<ClassName>();225 classNames.add(testClassName);226 clearGeneratedFiles(outputFolderName, classNames);227 }228 /**229 * As E2E generates test cases, we need delete the previous ones from previous runs, to make sure230 * we are running the latest generated.231 *232 * However, if you run everything from "org.", those existing tests from previous run will be loaded into233 * the JVM, and so checks for their presence after this is executed will pass... and so the E2E will fail234 */235 protected void clearCompiledFiles(ClassName testClassName){236 String byteCodePath = "target/test-classes/" + testClassName.getAsResourcePath();237 File compiledFile = new File(byteCodePath);238 boolean result = compiledFile.delete();239 }240 protected Class<?> loadClass(ClassName className){...
clearGeneratedFiles
Using AI Code Generation
1 public void testRunEM() throws Throwable {2 clearGeneratedFiles();3 runTestHandlingFlakyAndCompilation(4 (args) -> {5 },6 (results) -> {7 assertHasAtLeastOneOf(results.getRunResults(), "OK");8 }9 );10 }11}12The testRunEM() method will execute the EM test case and check if the results contains the string “OK”. You can use the following methods to check the results:13assertHasAtLeastOneOf(List<String> lines, String expected)14assertHasAtLeastOneOf(List<String> lines, String[] expected)15assertHasAtLeastOneOf(List<String> lines, String expected, int times)16assertHasAtLeastOneOf(List<String> lines, String[] expected, int times)17assertHasNotAnyOf(List<String> lines, String expected)18assertHasNotAnyOf(List<String> lines, String[] expected)19assertHasExactlyOneOf(List<String> lines, String expected)20assertHasExactlyOneOf(List<String> lines, String[] expected)21assertHasExactlyOneOf(List<String> lines, String expected, int times)22assertHasExactlyOneOf(List<String> lines, String[] expected, int times)23assertHasExactlyOneOf(List<String> lines, String expected, String expected2)24assertHasExactlyOneOf(List<String> lines, String[] expected, String expected2)25assertHasExactlyOneOf(List<String> lines, String expected, String expected2, int times)26assertHasExactlyOneOf(List<String> lines, String[] expected, String expected2, int times)27assertHasExactlyOneOf(List<String> lines, String expected, String expected2, String expected3)28assertHasExactlyOneOf(List<String> lines, String[] expected, String expected2, String expected3)29assertHasExactlyOneOf(List<String> lines, String expected, String expected2, String expected3, int times)30assertHasExactlyOneOf(List<String> lines, String[] expected, String expected2, String expected3, int times)31assertHasExactlyOneOf(List<String> lines, String expected, String expected2, String expected3, String expected4)32assertHasExactlyOneOf(List<String> lines, String[] expected, String expected2, String expected3
clearGeneratedFiles
Using AI Code Generation
1import org.junit.jupiter.api.AfterEach2import java.io.File3abstract class WsTestBase {4 fun cleanGeneratedFiles() {5 val dir = File("src/test/resources/generated/")6 if (dir.exists() && dir.isDirectory) {7 dir.deleteRecursively()8 }9 }10}11import com.foo.rest.examples.spring.ws.WsController12import org.evomaster.core.problem.rest.RestCallResult13import org.evomaster.core.problem.rest.RestIndividual14import org.evomaster.core.search.ActionResult15import org.evomaster.core.search.EvaluatedIndividual16import org.evomaster.core.search.service.SearchTimeController17import org.evomaster.e2etests.utils.WsTestBase18import org.evomaster.e2etests.utils.testBasics19import org.evomaster.e2etests.utils.testPost20import org.evomaster.e2etests.utils.testWs21import org.junit.jupiter.api.Test22class WsEMTest : WsTestBase() {23 fun testRunEM() {24 val result = testWs(baseUrlOfSut) { init ->25 .setProblemClass(WsController::class.java)26 .setOutputFormat(WsController.OutputFormat.XML)27 .setRunValidation(true)28 .setRunHeuristics(true)29 .setPopulationSize(20)30 .setStoppingCriterion(SearchTimeController.SearchTimeLimit.ofMinutes(10))31 .setHeuristicsForSQL(true)32 .setArchiveMutation(true)33 .setArchiveMutationStrength(0.5)34 .setArchiveMutationProbability(0.5)35 }36 assert(result.individuals.isNotEmpty())37 assert(result.individuals.size == 1)38 assert(result.individuals[0].fitness > 0.0)39 assert(result.individuals[0].individual.actions.isNotEmpty())40 assert(result.individuals[0].individual.seeActions().size == 2)41 assert(result.individuals[0].individual.seeActions()[0].seeGenes().size == 1)
clearGeneratedFiles
Using AI Code Generation
1@ExtendWith(WsTestBase.class)2public class Test_ExampleTest extends WsTestBase {3 public void testRunEM() throws Throwable {4 runTestHandlingFlakyAndCompilation(5 (args) -> {6 }7 );8 }9}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!