use of com.examples.with.different.packagename.continuous.Trivial in project evosuite by EvoSuite.
the class JobExecutorIntTest method testActualExecutionOfSchedule.
@Test(timeout = 90_000)
public void testActualExecutionOfSchedule() throws IOException {
Properties.TEST_SCAFFOLDING = true;
boolean storageOK = storage.isStorageOk();
assertTrue(storageOK);
storageOK = storage.createNewTmpFolders();
assertTrue(storageOK);
List<TestsOnDisk> data = storage.gatherGeneratedTestsOnDisk();
Assert.assertEquals(0, data.size());
ClassPathHandler.getInstance().changeTargetCPtoTheSameAsEvoSuite();
String classpath = ClassPathHandler.getInstance().getTargetProjectClasspath();
int cores = 1;
int memory = 1000;
int minutes = 1;
CtgConfiguration conf = new CtgConfiguration(memory, cores, minutes, 1, false, AvailableSchedule.SIMPLE);
JobExecutor exe = new JobExecutor(storage, classpath, conf);
JobDefinition simple = new JobDefinition(30, memory, com.examples.with.different.packagename.continuous.Simple.class.getName(), 0, null, null);
JobDefinition trivial = new JobDefinition(30, memory, com.examples.with.different.packagename.continuous.Trivial.class.getName(), 0, null, null);
assertTrue(simple.jobID < trivial.jobID);
List<JobDefinition> jobs = Arrays.asList(simple, trivial);
exe.executeJobs(jobs, cores);
exe.waitForJobs();
data = storage.gatherGeneratedTestsOnDisk();
// if Properties.TEST_SCAFFOLDING is enabled, we should have
// 4 java files (2 test cases and 2 scaffolding files), however
// 'storage' just returns the 2 test cases
boolean areThereFiles = (data.size() == 2);
boolean areThereTests = true;
// check if indeed they have tests
for (TestsOnDisk tod : data) {
String content = FileUtils.readFileToString(tod.testSuite);
areThereTests = areThereTests && content.contains("@Test") && !content.contains(TestSuiteWriter.NOT_GENERATED_TEST_NAME);
}
String msg = "Tmp folder: " + Properties.CTG_DIR + "\n";
if (!areThereFiles || !areThereTests) {
// build a better error message by looking at the log files
File logDir = storage.getTmpLogs();
msg += "Log folder: " + logDir.getAbsolutePath() + "\n";
List<File> files = FileIOUtils.getRecursivelyAllFilesInAllSubfolders(logDir, ".log");
msg += "# log files: " + files.size() + "\n";
for (File log : files) {
String content = null;
try {
content = FileUtils.readFileToString(log);
} catch (IOException e) {
msg += "Failed to read file " + log.getName() + " due to: " + e.toString() + "\n";
}
if (content != null) {
msg += "Content for file: " + log.getName() + "\n";
msg += "--------------------------------------------------" + "\n";
msg += content;
msg += "\n" + "--------------------------------------------------" + "\n";
}
}
}
Assert.assertEquals(msg, 2, data.size());
Assert.assertTrue(msg, areThereTests);
boolean deleted = storage.clean();
Assert.assertTrue(deleted);
}
use of com.examples.with.different.packagename.continuous.Trivial in project evosuite by EvoSuite.
the class JobExecutorIntTest method testEventSequenceWhenWrongSchedule.
@Test
public void testEventSequenceWhenWrongSchedule() throws InterruptedException {
boolean storageOK = storage.isStorageOk();
assertTrue(storageOK);
storageOK = storage.createNewTmpFolders();
assertTrue(storageOK);
List<TestsOnDisk> data = storage.gatherGeneratedTestsOnDisk();
Assert.assertEquals(0, data.size());
// no need to specify it, as com.examples are compiled with EvoSuite
String classpath = System.getProperty("java.class.path");
int cores = 1;
int memory = 1000;
int minutes = 10000;
CtgConfiguration conf = new CtgConfiguration(memory, cores, minutes, 1, false, AvailableSchedule.SIMPLE);
final JobExecutor exe = new JobExecutor(storage, classpath, conf);
JobDefinition simple = new JobDefinition(30, memory, Simple.class.getName(), 0, null, null);
JobDefinition trivial = new JobDefinition(30, memory, Trivial.class.getName(), 0, null, null);
JobDefinition ust = new JobDefinition(30, memory, UsingSimpleAndTrivial.class.getName(), 0, new HashSet<>(Arrays.asList(new String[] { Simple.class.getName(), Trivial.class.getName() })), null);
/*
* ust is in the middle, instead of last element.
* still, even if the schedule is wrong, the executor should be able
* to properly handle it
*/
final List<JobDefinition> jobs = Arrays.asList(simple, ust, trivial);
exe.initExecution(jobs);
Thread t = new Thread() {
@Override
public void run() {
exe.execute(jobs);
}
};
try {
t.start();
exe.doneWithJob(exe.pollJob());
exe.doneWithJob(exe.pollJob());
JobDefinition last = exe.pollJob();
exe.doneWithJob(last);
Assert.assertEquals(ust.cut, last.cut);
} finally {
t.interrupt();
}
storage.clean();
}
use of com.examples.with.different.packagename.continuous.Trivial in project evosuite by EvoSuite.
the class ProjectAnalyzerIntTest method testBranches.
@Test
public void testBranches() {
String[] cuts = new String[] { Simple.class.getName(), Trivial.class.getName() };
ProjectAnalyzer pa = new ProjectAnalyzer(cuts);
ProjectStaticData data = pa.analyze();
Assert.assertEquals(2, data.getTotalNumberOfClasses());
ClassInfo simple = data.getClassInfo(Simple.class.getName());
Assert.assertNotNull(simple);
Assert.assertEquals(2, simple.numberOfBranches);
ClassInfo trivial = data.getClassInfo(Trivial.class.getName());
Assert.assertNotNull(trivial);
Assert.assertEquals(1, trivial.numberOfBranches);
}
Aggregations