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

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

Source:WsTestBase.java Github

copy

Full Screen

...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 }...

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