mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 11:50:54 +07:00
IDEA-238461 fix + test added
GitOrigin-RevId: 5877a5e3b416869b1e427ca2d4af10b32ecb3ad7
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c12158e854
commit
24356ef062
@@ -30,6 +30,7 @@ import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.testFramework.*;
|
||||
import com.theoryinpractice.testng.configuration.TestNGConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.File;
|
||||
@@ -148,6 +149,17 @@ public abstract class BaseConfigurationTestCase extends JavaProjectTestCase {
|
||||
return (JUnitConfiguration)fromContext.getConfiguration();
|
||||
}
|
||||
|
||||
protected TestNGConfiguration createTestNGConfiguration(@NotNull PsiElement psiElement,
|
||||
@NotNull Class<? extends AbstractJavaTestConfigurationProducer> producerClass,
|
||||
@NotNull MapDataContext dataContext) {
|
||||
ConfigurationContext context = createContext(psiElement, dataContext);
|
||||
RunConfigurationProducer producer = RunConfigurationProducer.getInstance(producerClass);
|
||||
assert producer != null;
|
||||
ConfigurationFromContext fromContext = producer.createConfigurationFromContext(context);
|
||||
assertNotNull(fromContext);
|
||||
return (TestNGConfiguration)fromContext.getConfiguration();
|
||||
}
|
||||
|
||||
protected final <T extends RunConfiguration> T createConfiguration(@NotNull PsiElement psiElement) {
|
||||
return createConfiguration(psiElement, new MapDataContext());
|
||||
}
|
||||
|
||||
@@ -202,13 +202,13 @@ public class TestNGRunnableState extends JavaTestFrameworkRunnableState<TestNGCo
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
protected void collectPackagesToOpen(List<String> options) {
|
||||
TestData data = getConfiguration().getPersistantData();
|
||||
if (data.TEST_OBJECT == TestType.METHOD.getType() || data.TEST_OBJECT == TestType.CLASS.getType()) {
|
||||
if (TestType.METHOD.getType().equals(data.TEST_OBJECT) || TestType.CLASS.getType().equals(data.TEST_OBJECT)) {
|
||||
options.add(StringUtil.getPackageName(data.MAIN_CLASS_NAME));
|
||||
}
|
||||
else if (data.TEST_OBJECT == TestType.PACKAGE.getType()){
|
||||
else if (TestType.PACKAGE.getType().equals(data.TEST_OBJECT)){
|
||||
PsiPackage aPackage = JavaPsiFacade.getInstance(getConfiguration().getProject()).findPackage(data.PACKAGE_NAME);
|
||||
if (aPackage != null) {
|
||||
SourceScope sourceScope = data.getScope().getSourceScope(getConfiguration());
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
package com.intellij.testng.integration;
|
||||
|
||||
import com.intellij.execution.ExecutionException;
|
||||
import com.intellij.java.execution.AbstractTestFrameworkCompilingIntegrationTest;
|
||||
import com.intellij.openapi.roots.ContentEntry;
|
||||
import com.intellij.openapi.roots.LanguageLevelModuleExtension;
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.testFramework.MapDataContext;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.theoryinpractice.testng.configuration.*;
|
||||
import com.theoryinpractice.testng.model.TestData;
|
||||
import com.theoryinpractice.testng.model.TestType;
|
||||
import jetbrains.buildServer.messages.serviceMessages.TestStarted;
|
||||
import org.jetbrains.idea.maven.aether.ArtifactRepositoryManager;
|
||||
import org.jetbrains.jps.model.library.JpsMavenRepositoryLibraryDescriptor;
|
||||
|
||||
import static com.intellij.execution.testframework.TestSearchScope.SINGLE_MODULE;
|
||||
|
||||
public class TestNGModuleInfoIntegrationTest extends AbstractTestFrameworkCompilingIntegrationTest {
|
||||
|
||||
@Override
|
||||
protected String getTestContentRoot() {
|
||||
return VfsUtilCore
|
||||
.pathToUrl(PlatformTestUtil.getCommunityPath() + "/plugins/testng_rt/tests/testData/integration/forkProjectWithModuleInfoTestNG");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupModule() throws Exception {
|
||||
super.setupModule();
|
||||
final ArtifactRepositoryManager repoManager = getRepoManager();
|
||||
|
||||
ModuleRootModificationUtil.updateModel(myModule, model -> {
|
||||
String contentUrl = getTestContentRoot();
|
||||
ContentEntry contentEntry = model.addContentEntry(contentUrl);
|
||||
String contentUrlSrc = contentUrl + "/source";
|
||||
contentEntry.addSourceFolder(contentUrlSrc, false);
|
||||
model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(LanguageLevel.JDK_11);
|
||||
});
|
||||
|
||||
JpsMavenRepositoryLibraryDescriptor testNGLib =
|
||||
new JpsMavenRepositoryLibraryDescriptor("org.testng", "testng", "6.8");
|
||||
addMavenLibs(myModule, testNGLib, repoManager);
|
||||
}
|
||||
|
||||
public void testModuleInfoInSourceRoot() throws ExecutionException {
|
||||
PsiPackage defaultPackage = JavaPsiFacade.getInstance(myProject).findPackage("p").getParentPackage();
|
||||
final MapDataContext dataContext = new MapDataContext();
|
||||
dataContext.put("myModule", myModule);
|
||||
TestNGConfiguration configuration =
|
||||
createTestNGConfiguration(defaultPackage, AbstractTestNGPackageConfigurationProducer.class, dataContext);
|
||||
configuration.setUseModulePath(true);
|
||||
configuration.setWorkingDirectory("$MODULE_WORKING_DIR$");
|
||||
configuration.setSearchScope(SINGLE_MODULE);
|
||||
TestData dataTNG = configuration.getPersistantData();
|
||||
dataTNG.TEST_OBJECT = new String(TestType.PACKAGE.getType());
|
||||
final ProcessOutput output = doStartTestsProcess(configuration);
|
||||
assertTrue(output.sys.toString().contains("testng"));
|
||||
assertSize(2, ContainerUtil.filter(output.messages, TestStarted.class::isInstance));
|
||||
assertEmpty(output.err);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
module forkProjectWithModuleInfoTestNG {
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package p;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
public class MyTest1 {
|
||||
@Test
|
||||
public void emptyTest1() { }
|
||||
|
||||
@Test
|
||||
public void emptyTest2() { }
|
||||
}
|
||||
Reference in New Issue
Block a user