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

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

Source:WsTestBase.java Github

copy

Full Screen

...12import org.evomaster.core.Main;13import org.evomaster.core.StaticCounter;14import org.evomaster.core.logging.TestLoggingUtil;15import org.evomaster.core.output.OutputFormat;16import org.evomaster.core.output.compiler.CompilerForTestGenerated;17import org.evomaster.core.problem.httpws.service.HttpWsIndividual;18import org.evomaster.core.remote.service.RemoteController;19import org.evomaster.core.search.Solution;20import org.junit.jupiter.api.AfterAll;21import org.junit.jupiter.api.BeforeEach;22import org.junit.platform.launcher.listeners.TestExecutionSummary;23import java.io.File;24import java.io.PrintWriter;25import java.io.StringWriter;26import java.time.Duration;27import java.util.ArrayList;28import java.util.Arrays;29import java.util.List;30import java.util.function.Consumer;31import static org.junit.jupiter.api.Assertions.*;32public abstract class WsTestBase {33 protected static InstrumentedSutStarter embeddedStarter;34 protected static String baseUrlOfSut;35 protected static SutController controller;36 protected static RemoteController remoteController;37 protected static int controllerPort;38 private final static int STARTING_SEED = 42;39 protected int defaultSeed = STARTING_SEED;40 public final static String TESTS_OUTPUT_ROOT_FOLDER = "target/em-tests/";41 @AfterAll42 public static void tearDown() {43 assertTimeoutPreemptively(Duration.ofMinutes(2), () -> {44 boolean stopped = remoteController.stopSUT();45 stopped = embeddedStarter.stop() && stopped;46 assertTrue(stopped);47 });48 SimpleLogger.setThreshold(SimpleLogger.Level.INFO);49 }50 @BeforeEach51 public void initTest() {52 //in case it was modified in a previous test in the same class53 defaultSeed = STARTING_SEED;54 StaticCounter.Companion.reset();55 assertTimeoutPreemptively(Duration.ofMinutes(2), () -> {56 boolean reset = remoteController.resetSUT();57 assertTrue(reset);58 });59 SimpleLogger.setThreshold(SimpleLogger.Level.DEBUG);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,...

Full Screen

Full Screen

compile

Using AI Code Generation

copy

Full Screen

1 def "test WS POST /api/echo"(){2 {3 }4 '''.stripIndent()5 def response = sendPost("/api/echo", body)6 }7 def "test WS GET /api/echo"(){8 {9 }10 '''.stripIndent()11 def response = sendGet("/api/echo?id=1&name=foo&type=bar")12 }13 def "test WS GET /api/echo with query param"(){14 {15 }16 '''.stripIndent()17 def response = sendGet("/api/echo?id=1&name=foo&type=bar")18 }19 def "test WS GET /api/echo with query param and path param"(){20 {21 }22 '''.stripIndent()23 def response = sendGet("/api/echo/1?name=foo&type=bar")24 }25 def "test WS GET /api/echo with path param"(){26 {27 }28 '''.stripIndent()29 def response = sendGet("/api/echo/1")30 }31 def "test WS GET /api/echo with path param and query param"(){32 {

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