How to use outputFolderPath method of org.evomaster.e2etests.utils.WsTestBase class

Best EvoMaster code snippet using org.evomaster.e2etests.utils.WsTestBase.outputFolderPath

Source:WsTestBase.java Github

copy

Full Screen

...60 }61 protected Injector init(List<String> args) {62 return Main.init(args.toArray(new String[0]));63 }64 protected String outputFolderPath(String outputFolderName){65 return TESTS_OUTPUT_ROOT_FOLDER + outputFolderName;66 }67 protected void runAndCheckDeterminism(int iterations, Consumer<List<String>> lambda){68 List<String> args = new ArrayList<>(Arrays.asList(69 "--createTests", "false",70 "--seed", "42",71 "--showProgress", "false",72 "--avoidNonDeterministicLogs", "true",73 "--sutControllerPort", "" + controllerPort,74 "--maxActionEvaluations", "" + iterations,75 "--stoppingCriterion", "FITNESS_EVALUATIONS",76 "--useTimeInFeedbackSampling" , "false"77 ));78 StaticCounter.Companion.reset();79 String firstRun = TestLoggingUtil.Companion.runWithDeterministicLogger(80 () -> {lambda.accept(args); return Unit.INSTANCE;}81 );82 StaticCounter.Companion.reset();83 String secondRun = TestLoggingUtil.Companion.runWithDeterministicLogger(84 () -> {lambda.accept(args); return Unit.INSTANCE;}85 );86 assertEquals(firstRun, secondRun);87 }88 protected void runTestHandlingFlaky(89 String outputFolderName,90 String fullClassName,91 int iterations,92 boolean createTests,93 Consumer<List<String>> lambda) throws Throwable{94 runTestHandlingFlaky(outputFolderName, fullClassName, iterations, createTests, lambda, 3);95 }96 protected void runTestHandlingFlaky(97 String outputFolderName,98 String fullClassName,99 int iterations,100 boolean createTests,101 Consumer<List<String>> lambda,102 int timeoutMinutes) throws Throwable{103 runTestHandlingFlaky(outputFolderName, fullClassName, null, iterations, createTests, lambda, timeoutMinutes);104 }105 protected void runTestHandlingFlaky(106 String outputFolderName,107 String fullClassName,108 List<String> terminations,109 int iterations,110 boolean createTests,111 Consumer<List<String>> lambda,112 int timeoutMinutes) throws Throwable{113 List<ClassName> classNames = new ArrayList<>();114 String splitType = "";115 if(terminations == null || terminations.isEmpty()){116 classNames.add(new ClassName(fullClassName));117 splitType = "NONE";118 } else {119 for (String termination : terminations) {120 classNames.add(new ClassName(fullClassName + termination));121 }122 splitType = "CLUSTER";123 }124 /*125 Years have passed, still JUnit 5 does not handle global test timeouts :(126 https://github.com/junit-team/junit5/issues/80127 */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){241 try {242 return this.getClass().getClassLoader().loadClass(className.getFullNameWithDots());243 } catch (ClassNotFoundException e) {244 return null;245 }246 }247 protected void compile(String outputFolderName){248 CompilerForTestGenerated.INSTANCE.compile(249 OutputFormat.KOTLIN_JUNIT_5,250 new File(outputFolderPath(outputFolderName)),251 new File("target/test-classes")252 );253 }254 protected List<String> getArgsWithCompilation(int iterations, String outputFolderName, ClassName testClassName){255 return getArgsWithCompilation(iterations, outputFolderName, testClassName, true);256 }257 protected List<String> getArgsWithCompilation(int iterations, String outputFolderName, ClassName testClassName, boolean createTests){258 return getArgsWithCompilation(iterations, outputFolderName, testClassName, createTests, "NONE", "FALSE");259 }260 protected List<String> getArgsWithCompilation(int iterations, String outputFolderName, ClassName testClassName, boolean createTests, String split, String summary){261 return new ArrayList<>(Arrays.asList(262 "--createTests", "" + createTests,263 "--seed", "" + defaultSeed,264 "--useTimeInFeedbackSampling" , "false",265 "--sutControllerPort", "" + controllerPort,266 "--maxActionEvaluations", "" + iterations,267 "--stoppingCriterion", "FITNESS_EVALUATIONS",268 "--outputFolder", outputFolderPath(outputFolderName),269 "--outputFormat", OutputFormat.KOTLIN_JUNIT_5.toString(),270 //FIXME: should avoid deprecated option, but then need TODO update how class files are deleted from FS271 "--testSuiteFileName", testClassName.getFullNameWithDots(),272 "--testSuiteSplitType", split,273 "--expectationsActive", "TRUE",274 "--executiveSummary", summary275 ));276 }277 /**278 * Unfortunately JUnit 5 does not handle flaky tests, and Maven is not upgraded yet.279 * See https://github.com/junit-team/junit5/issues/1558#issuecomment-414701182280 *281 * TODO: once that issue is fixed (if it will ever be fixed), then this method282 * will no longer be needed....

Full Screen

Full Screen

outputFolderPath

Using AI Code Generation

copy

Full Screen

1[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ evomaster-client-java ---2[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ evomaster-client-java ---3[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ evomaster-client-java ---4[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ evomaster-client-java ---5[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ evomaster-client-java ---6[WARNING] testThatSutIsUp(org.evomaster.client.java.controller.EmbeddedSutControllerTest) Time elapsed: 0.001 s <<< ERROR!7 at org.evomaster.client.java.controller.EmbeddedSutControllerTest.testThatSutIsUp(EmbeddedSutControllerTest.java:31)

Full Screen

Full Screen

outputFolderPath

Using AI Code Generation

copy

Full Screen

1static final WsTestBase testBase = new WsTestBase(){2 public String outputFolderPath(){3 return "outputFolder";4 }5};6File file = new File("outputFolder/fileName.json");7String json = FileUtils.readFileToString(file, StandardCharsets.UTF_8);

Full Screen

Full Screen

outputFolderPath

Using AI Code Generation

copy

Full Screen

1package org.evomaster.e2etests.spring.examples.ws;2import com.foo.rest.examples.spring.ws.WsController;3import io.restassured.RestAssured;4import org.evomaster.client.java.controller.EmbeddedSutController;5import org.evomaster.client.java.controller.InstrumentedSutStarter;6import org.evomaster.client.java.controller.api.dto.database.operations.DatabaseCommandDto;7import org.evomaster.client.java.controller.api.dto.database.operations.InsertionDto;8import org.evomaster.client.java.controller.api.dto.database.operations.SqlScriptDto;9import org.evomaster.client.java.controller.api.dto.database.schema.DbSchemaDto;10import org.evomaster.client.java.controller.api.dto.database.schema.TableDto;11import org.evomaster.client.java.controller.api.dto.database.schema.TableEntryDto;12import org.evomaster.client.java.controller.api.dto.database.schema.TableSchemaDto;13import org.evomaster.client.java.controller.api.dto.problem.ProblemInfoDto;14import org.evomaster.client.java.controller.api.dto.problem.RestProblemDto;15import org.evomaster.client.java.controller.api.dto.sut.SutInfoDto;16import org.evomaster.client.java.controller.internal.db.SqlScriptRunner;17import org.evomaster.client.java.controller.internal.db.h2.H2Controller;18import org.evomaster.client.java.controller.internal.db.h2.H2EmbeddedDatabase;19import org.evomaster.client.java.controller.internal.db.h2.H2SchemaExtractor;20import org.evomaster.client.java.controller.internal.db.schema.SqlScriptExecutor;21import org.evomaster.client.java.controller.internal.db.schema.SqlScriptExecutorImpl;22import org.evomaster.client.java.controller.internal.db.schema.SqlScriptParser;23import org.evomaster.client.java.controller.internal.db.schema.SqlScriptParserImpl;24import org.evomaster.client.java.controller.internal.db.schema.SqlScriptRunnerImpl;25import org.evomaster.client.java.controller.internal.db.schema.TableSchema;26import org.evomaster.client.java.controller.internal.db.schema.TableSchemaExtractor;27import org.evomaster.client.java.controller.internal.db.schema.TableSchemaExtractorImpl;28import org.evomaster.client.java.controller.internal

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful