use of com.intellij.execution.testframework.SourceScope in project intellij-community by JetBrains.
the class TestObject method createJavaParameters.
@Override
protected JavaParameters createJavaParameters() throws ExecutionException {
JavaParameters javaParameters = super.createJavaParameters();
javaParameters.setMainClass(JUnitConfiguration.JUNIT_START_CLASS);
javaParameters.getProgramParametersList().add(JUnitStarter.IDE_VERSION + JUnitStarter.VERSION);
final StringBuilder buf = new StringBuilder();
collectListeners(javaParameters, buf, IDEAJUnitListener.EP_NAME, "\n");
if (buf.length() > 0) {
try {
myListenersFile = FileUtil.createTempFile("junit_listeners_", "", true);
javaParameters.getProgramParametersList().add("@@" + myListenersFile.getPath());
FileUtil.writeToFile(myListenersFile, buf.toString().getBytes(CharsetToolkit.UTF8_CHARSET));
} catch (IOException e) {
LOG.error(e);
}
}
final Project project = getConfiguration().getProject();
final SourceScope sourceScope = getSourceScope();
if (isJUnit5(getConfiguration().getConfigurationModule().getModule(), sourceScope, project)) {
javaParameters.getProgramParametersList().add(JUnitStarter.JUNIT5_PARAMETER);
javaParameters.getClassPath().add(PathUtil.getJarPathForClass(JUnit5IdeaTestRunner.class));
final PathsList classPath = javaParameters.getClassPath();
classPath.add(PathUtil.getJarPathForClass(TestExecutionListener.class));
classPath.add(PathUtil.getJarPathForClass(JupiterTestEngine.class));
classPath.add(PathUtil.getJarPathForClass(JUnitException.class));
classPath.add(PathUtil.getJarPathForClass(TestEngine.class));
classPath.add(PathUtil.getJarPathForClass(JUnitPlatform.class));
try {
JUnitUtil.getTestCaseClass(sourceScope);
classPath.add(PathUtil.getJarPathForClass(VintageTestEngine.class));
} catch (JUnitUtil.NoJUnitException ignore) {
}
}
return javaParameters;
}
use of com.intellij.execution.testframework.SourceScope in project intellij-community by JetBrains.
the class TestNGTestPattern method fillTestObjects.
public static void fillTestObjects(final Map<PsiClass, Map<PsiMethod, List<String>>> classes, final Set<String> patterns, final TestSearchScope testSearchScope, final ModuleBasedConfiguration config, final GlobalSearchScope searchScope) throws CantRunException {
for (final String pattern : patterns) {
final String className;
final String methodName;
if (pattern.contains(",")) {
methodName = StringUtil.getShortName(pattern, ',');
className = StringUtil.getPackageName(pattern, ',');
} else {
className = pattern;
methodName = null;
}
final PsiClass psiClass = ApplicationManager.getApplication().runReadAction(new Computable<PsiClass>() {
@Nullable
@Override
public PsiClass compute() {
return ClassUtil.findPsiClass(PsiManager.getInstance(config.getProject()), className.replace('/', '.'), null, true, searchScope);
}
});
if (psiClass != null) {
final Boolean hasTest = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
@Override
public Boolean compute() {
return TestNGUtil.hasTest(psiClass);
}
});
if (hasTest) {
if (StringUtil.isEmpty(methodName)) {
calculateDependencies(null, classes, searchScope, psiClass);
} else {
collectTestMethods(classes, psiClass, methodName, searchScope);
}
} else {
throw new CantRunException("No tests found in class " + className);
}
}
}
if (classes.size() != patterns.size()) {
final List<Pattern> compilePatterns = new ArrayList<>();
for (String p : patterns) {
final Pattern compilePattern;
try {
compilePattern = Pattern.compile(p);
} catch (PatternSyntaxException e) {
continue;
}
compilePatterns.add(compilePattern);
}
final SourceScope sourceScope = testSearchScope.getSourceScope(config);
TestClassFilter projectFilter = new TestClassFilter(sourceScope != null ? sourceScope.getGlobalSearchScope() : GlobalSearchScope.allScope(config.getProject()), config.getProject(), true, true) {
@Override
public boolean isAccepted(PsiClass psiClass) {
if (super.isAccepted(psiClass)) {
final String qualifiedName = ReadAction.compute(psiClass::getQualifiedName);
LOG.assertTrue(qualifiedName != null);
for (Pattern pattern : compilePatterns) {
if (pattern.matcher(qualifiedName).matches())
return true;
}
}
return false;
}
};
calculateDependencies(null, classes, searchScope, TestNGUtil.getAllTestClasses(projectFilter, false));
if (classes.size() == 0) {
throw new CantRunException("No tests found in for patterns \"" + StringUtil.join(patterns, " || ") + '\"');
}
}
}
use of com.intellij.execution.testframework.SourceScope in project intellij-community by JetBrains.
the class TestPackage method createJavaParameters.
@Override
protected JavaParameters createJavaParameters() throws ExecutionException {
final JavaParameters javaParameters = super.createJavaParameters();
final JUnitConfiguration.Data data = getConfiguration().getPersistentData();
final Project project = getConfiguration().getProject();
final SourceScope sourceScope = data.getScope().getSourceScope(getConfiguration());
if (sourceScope == null || !isJUnit5(getConfiguration().getConfigurationModule().getModule(), sourceScope, project)) {
//check for junit 5
JUnitUtil.checkTestCase(sourceScope, project);
}
createTempFiles(javaParameters);
createServerSocket(javaParameters);
return javaParameters;
}
Aggregations