use of org.evosuite.junit.DetermineSUT.NoJUnitClassException in project evosuite by EvoSuite.
the class ExtendSuiteAction method addTestJob.
// @Override
// public void selectionChanged(IAction action, ISelection selection) {
// currentSelection.clear();
//
// if (selection instanceof IStructuredSelection) {
// IStructuredSelection sel = (IStructuredSelection) selection;
//
// for (Object o : sel.toList()) {
// if (o instanceof IJavaElement) {
// IJavaElement jEl = (IJavaElement) o;
// try {
// IResource jRes = jEl.getCorrespondingResource();
// if (jRes != null) {
// jRes.accept(new IResourceVisitor() {
// @Override
// public boolean visit(IResource resource)
// throws CoreException {
// if ("java".equals(resource.getFileExtension()))
// currentSelection.add(resource);
// return true;
// }
// });
// }
// } catch (JavaModelException e) {
// System.err.println("Error while traversing resources!" + e);
// } catch (CoreException e) {
// System.err.println("Error while traversing resources!" + e);
// }
// }
// }
// }
// }
//
// @Override
// public void run(IAction action) {
// if (currentSelection.isEmpty()) {
// MessageDialog.openError(shell, "Evosuite",
// "Unable to generate test cases for selection: Cannot find .java files.");
// } else if (currentSelection.size() > 1) {
// MessageDialog.openError(shell, "Evosuite",
// "Please only select one class at a time.");
// } else {
//
// for (IResource res : currentSelection) {
// IProject proj = res.getProject();
// fixJUnitClassPath(JavaCore.create(proj));
// generateTests(res);
// }
// }
// }
/**
* Add a new test generation job to the job queue
*
* @param target
*/
@Override
protected void addTestJob(final IResource target) {
IJavaElement element = JavaCore.create(target);
IJavaElement packageElement = element.getParent();
String packageName = packageElement.getElementName();
final String suiteClass = (!packageName.equals("") ? packageName + "." : "") + target.getName().replace(".java", "").replace(File.separator, ".");
System.out.println("Building new job for " + suiteClass);
DetermineSUT det = new DetermineSUT();
IJavaProject jProject = JavaCore.create(target.getProject());
try {
String classPath = target.getWorkspace().getRoot().findMember(jProject.getOutputLocation()).getLocation().toOSString();
String SUT = det.getSUTName(suiteClass, classPath);
// choose
SelectionDialog typeDialog = JavaUI.createTypeDialog(shell, new ProgressMonitorDialog(shell), target.getProject(), IJavaElementSearchConstants.CONSIDER_CLASSES, false);
Object[] sutDefault = new Object[1];
sutDefault[0] = SUT;
typeDialog.setInitialSelections(sutDefault);
typeDialog.setTitle("Please select the class under test");
typeDialog.open();
// Type selected by the user
Object[] result = typeDialog.getResult();
if (result.length > 0) {
SourceType sourceType = (SourceType) result[0];
SUT = sourceType.getFullyQualifiedName();
} else {
return;
}
Job job = new TestExtensionJob(shell, target, SUT, suiteClass);
job.setPriority(Job.SHORT);
IResourceRuleFactory ruleFactory = ResourcesPlugin.getWorkspace().getRuleFactory();
ISchedulingRule rule = ruleFactory.createRule(target.getProject());
// IFolder folder = proj.getFolder(ResourceUtil.EVOSUITE_FILES);
job.setRule(rule);
job.setUser(true);
// start as soon as possible
job.schedule();
} catch (JavaModelException e) {
e.printStackTrace();
} catch (NoJUnitClassException e) {
MessageDialog.openError(shell, "Evosuite", "Cannot find JUnit tests in " + suiteClass);
}
}
Aggregations