testng integration tests

This commit is contained in:
Anna.Kozlova
2018-04-05 17:20:15 +02:00
parent 8e42a480ab
commit bf90fea9c5
13 changed files with 189 additions and 106 deletions
+1
View File
@@ -670,6 +670,7 @@
<module fileurl="file://$PROJECT_DIR$/plugins/terminal/intellij.terminal.iml" filepath="$PROJECT_DIR$/plugins/terminal/intellij.terminal.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/testng/intellij.testng.iml" filepath="$PROJECT_DIR$/plugins/testng/intellij.testng.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/testng_rt/intellij.testng.rt.iml" filepath="$PROJECT_DIR$/plugins/testng_rt/intellij.testng.rt.iml" />
<module fileurl="file://$PROJECT_DIR$/plugins/testng_rt/tests/intellij.testng.rt.tests.iml" filepath="$PROJECT_DIR$/plugins/testng_rt/tests/intellij.testng.rt.tests.iml" />
<module fileurl="file://$PROJECT_DIR$/build/dependencies/intellij.tools.dependencies.iml" filepath="$PROJECT_DIR$/build/dependencies/intellij.tools.dependencies.iml" />
<module fileurl="file://$PROJECT_DIR$/build/dependencies/gradle-api-deps/intellij.tools.dependencies.gradle.iml" filepath="$PROJECT_DIR$/build/dependencies/gradle-api-deps/intellij.tools.dependencies.gradle.iml" />
<module fileurl="file://$PROJECT_DIR$/tools/index-tools/intellij.tools.index.iml" filepath="$PROJECT_DIR$/tools/index-tools/intellij.tools.index.iml" />
@@ -7,6 +7,7 @@ import com.intellij.execution.configurations.ConfigurationFactory;
import com.intellij.execution.configurations.JavaRunConfigurationModule;
import com.intellij.execution.configurations.ModuleBasedConfiguration;
import com.intellij.execution.configurations.RefactoringListenerProvider;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.execution.testframework.TestSearchScope;
import com.intellij.execution.testframework.sm.runner.SMRunnerConsolePropertiesProvider;
import com.intellij.openapi.util.InvalidDataException;
@@ -52,6 +53,10 @@ public abstract class JavaTestConfigurationBase extends ModuleBasedConfiguration
public abstract TestSearchScope getTestSearchScope();
public abstract void setSearchScope(TestSearchScope searchScope);
@Nullable
@Override
public abstract JavaTestFrameworkRunnableState<? extends JavaTestConfigurationBase> getState(@NotNull Executor executor, @NotNull ExecutionEnvironment environment) throws ExecutionException;
@Nullable
@Override
public ShortenCommandLine getShortenCommandLine() {
@@ -469,4 +469,5 @@ public abstract class JavaTestFrameworkRunnableState<T extends
}
}
public void appendRepeatMode() throws ExecutionException { }
}
+1
View File
@@ -55,5 +55,6 @@
<orderEntry type="module" module-name="intellij.platform.builtInServer" scope="TEST" />
<orderEntry type="module" module-name="intellij.platform.testExtensions" scope="TEST" />
<orderEntry type="module" module-name="intellij.platform.configurationStore.impl" scope="TEST" />
<orderEntry type="module" module-name="intellij.java.aetherDependencyResolver" scope="TEST" />
</component>
</module>
@@ -1,35 +1,18 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.junit4;
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.java.execution;
import com.intellij.openapi.compiler.CompilerMessage;
import com.intellij.openapi.compiler.CompilerMessageCategory;
import com.intellij.openapi.roots.ModuleRootModificationUtil;
import com.intellij.testFramework.CompilerTester;
import org.jetbrains.idea.maven.aether.ArtifactRepositoryManager;
import org.jetbrains.jps.model.library.JpsMavenRepositoryLibraryDescriptor;
import java.util.List;
import java.util.stream.Collectors;
public abstract class JUnitAbstractCompilingIntegrationTest extends JUnitAbstractIntegrationTest {
public abstract class AbstractTestFrameworkCompilingIntegrationTest extends AbstractTestFrameworkIntegrationTest {
private CompilerTester myCompilerTester;
protected abstract String getTestContentRoot();
protected abstract JpsMavenRepositoryLibraryDescriptor[] getRequiredLibs();
@Override
protected void setUp() throws Exception {
@@ -38,10 +21,7 @@ public abstract class JUnitAbstractCompilingIntegrationTest extends JUnitAbstrac
model -> model.addContentEntry(getTestContentRoot())
.addSourceFolder(getTestContentRoot() + "/test", true));
final ArtifactRepositoryManager repoManager = getRepoManager();
for (JpsMavenRepositoryLibraryDescriptor descriptor : getRequiredLibs()) {
addLibs(myModule, descriptor, repoManager );
}
setupLibraries();
myCompilerTester = new CompilerTester(myModule);
List<CompilerMessage> compilerMessages = myCompilerTester.rebuild();
assertEmpty(compilerMessages.stream()
@@ -49,6 +29,8 @@ public abstract class JUnitAbstractCompilingIntegrationTest extends JUnitAbstrac
.collect(Collectors.toSet()));
}
protected void setupLibraries() throws Exception { }
@Override
protected void tearDown() throws Exception {
try {
@@ -1,38 +1,19 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.junit4;
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.java.execution;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.Executor;
import com.intellij.execution.ProgramRunnerUtil;
import com.intellij.execution.*;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.configurations.JavaParameters;
import com.intellij.execution.configurations.RunConfiguration;
import com.intellij.execution.executors.DefaultRunExecutor;
import com.intellij.execution.impl.RunManagerImpl;
import com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl;
import com.intellij.execution.junit.JUnitConfiguration;
import com.intellij.execution.junit.TestObject;
import com.intellij.execution.process.OSProcessHandler;
import com.intellij.execution.process.ProcessAdapter;
import com.intellij.execution.process.ProcessEvent;
import com.intellij.execution.process.ProcessOutputTypes;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.execution.testframework.SearchForTestsTask;
import com.intellij.java.execution.BaseConfigurationTestCase;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.progress.EmptyProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
@@ -56,7 +37,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
public abstract class JUnitAbstractIntegrationTest extends BaseConfigurationTestCase {
public abstract class AbstractTestFrameworkIntegrationTest extends BaseConfigurationTestCase {
public static ProcessOutput doStartTestsProcess(RunConfiguration configuration) throws ExecutionException {
Executor executor = DefaultRunExecutor.getRunExecutorInstance();
Project project = configuration.getProject();
@@ -64,7 +45,7 @@ public abstract class JUnitAbstractIntegrationTest extends BaseConfigurationTest
settings = new RunnerAndConfigurationSettingsImpl(RunManagerImpl.getInstanceImpl(project), configuration, false);
ExecutionEnvironment
environment = new ExecutionEnvironment(executor, ProgramRunnerUtil.getRunner(DefaultRunExecutor.EXECUTOR_ID, settings), settings, project);
TestObject state = ((JUnitConfiguration)configuration).getState(executor, environment);
JavaTestFrameworkRunnableState state = ((JavaTestConfigurationBase)configuration).getState(executor, environment);
state.appendRepeatMode();
JavaParameters parameters = state.getJavaParameters();
@@ -151,9 +132,9 @@ public abstract class JUnitAbstractIntegrationTest extends BaseConfigurationTest
}
public static class ProcessOutput {
List<String> out = new ArrayList<>();
public List<String> out = new ArrayList<>();
public List<String> err = new ArrayList<>();
List<String> sys = new ArrayList<>();
List<ServiceMessage> messages = new ArrayList<>();
public List<String> sys = new ArrayList<>();
public List<ServiceMessage> messages = new ArrayList<>();
}
}
@@ -15,7 +15,9 @@
*/
package com.intellij.junit4;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.junit.JUnitConfiguration;
import com.intellij.java.execution.AbstractTestFrameworkIntegrationTest;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl;
import com.intellij.openapi.roots.CompilerModuleExtension;
@@ -24,8 +26,9 @@ import com.intellij.openapi.roots.ModuleRootModificationUtil;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiMethod;
import com.intellij.testFramework.EdtTestUtil;
import com.intellij.testFramework.EdtRule;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.testFramework.RunsInEdt;
import org.jetbrains.jps.model.library.JpsMavenRepositoryLibraryDescriptor;
import org.junit.After;
import org.junit.Before;
@@ -39,12 +42,14 @@ import java.io.File;
import java.util.Arrays;
import java.util.Collection;
@RunsInEdt
@RunWith(Parameterized.class)
public class JUnit4IntegrationTest extends JUnitAbstractIntegrationTest {
public class JUnit4IntegrationTest extends AbstractTestFrameworkIntegrationTest {
public static final String CLASS_NAME = "a.Test1";
private static final String METHOD_NAME = "simple";
@Rule public final EdtRule edtRule = new EdtRule();
@Rule public final TestName myNameRule = new TestName();
@Parameterized.Parameters(name = "{0}")
@@ -67,35 +72,31 @@ public class JUnit4IntegrationTest extends JUnitAbstractIntegrationTest {
public String myJUnitVersion;
@Before
public void before() {
EdtTestUtil.runInEdtAndWait(() -> {
setUp();
Module module = createEmptyModule();
String communityPath = PlatformTestUtil.getCommunityPath().replace(File.separatorChar, '/');
String methodName = myNameRule.getMethodName();
methodName = methodName.substring(0, methodName.indexOf("["));
String testDataPath = communityPath + File.separator + "plugins" + File.separator + "junit5_rt_tests" +
File.separator + "testData" + File.separator + "integration" + File.separator + methodName;
addLibs(module, new JpsMavenRepositoryLibraryDescriptor("junit", "junit", myJUnitVersion), getRepoManager());
public void before() throws Exception {
setUp();
Module module = createEmptyModule();
String communityPath = PlatformTestUtil.getCommunityPath().replace(File.separatorChar, '/');
String methodName = myNameRule.getMethodName();
methodName = methodName.substring(0, methodName.indexOf("["));
String testDataPath = communityPath + File.separator + "plugins" + File.separator + "junit5_rt_tests" +
File.separator + "testData" + File.separator + "integration" + File.separator + methodName;
ModuleRootModificationUtil.setModuleSdk(module, JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk());
ModuleRootModificationUtil.updateModel(module, model -> {
ContentEntry contentEntry = model.addContentEntry(VfsUtilCore.pathToUrl(testDataPath));
contentEntry.addSourceFolder(VfsUtilCore.pathToUrl(testDataPath + File.separator + "test"), true);
CompilerModuleExtension moduleExtension = model.getModuleExtension(CompilerModuleExtension.class);
moduleExtension.inheritCompilerOutputPath(false);
moduleExtension.setCompilerOutputPathForTests(VfsUtilCore.pathToUrl(testDataPath + File.separator + "out"));
});
addLibs(module, new JpsMavenRepositoryLibraryDescriptor("junit", "junit", myJUnitVersion), getRepoManager());
ModuleRootModificationUtil.setModuleSdk(module, JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk());
ModuleRootModificationUtil.updateModel(module, model -> {
ContentEntry contentEntry = model.addContentEntry(VfsUtilCore.pathToUrl(testDataPath));
contentEntry.addSourceFolder(VfsUtilCore.pathToUrl(testDataPath + File.separator + "test"), true);
CompilerModuleExtension moduleExtension = model.getModuleExtension(CompilerModuleExtension.class);
moduleExtension.inheritCompilerOutputPath(false);
moduleExtension.setCompilerOutputPathForTests(VfsUtilCore.pathToUrl(testDataPath + File.separator + "out"));
});
}
@After
public void after() {
EdtTestUtil.runInEdtAndWait(() -> {
JavaAwareProjectJdkTableImpl.removeInternalJdkInTests();
tearDown();
});
public void after() throws Exception {
JavaAwareProjectJdkTableImpl.removeInternalJdkInTests();
tearDown();
}
@Override
@@ -104,21 +105,19 @@ public class JUnit4IntegrationTest extends JUnitAbstractIntegrationTest {
}
@Test
public void ignoredTestMethod() {
EdtTestUtil.runInEdtAndWait(() -> {
PsiClass psiClass = findClass(getModule1(), CLASS_NAME);
assertNotNull(psiClass);
PsiMethod testMethod = psiClass.findMethodsByName(METHOD_NAME, false)[0];
JUnitConfiguration configuration = createConfiguration(testMethod);
ProcessOutput processOutput = doStartTestsProcess(configuration);
String testOutput = processOutput.out.toString();
assertEmpty(processOutput.err);
switch (myJUnitVersion) {
case "4.4": case "4.5": break; //shouldn't work for old versions
default:
assertTrue(testOutput, testOutput.contains("Test1"));
}
});
public void ignoredTestMethod() throws ExecutionException {
PsiClass psiClass = findClass(getModule1(), CLASS_NAME);
assertNotNull(psiClass);
PsiMethod testMethod = psiClass.findMethodsByName(METHOD_NAME, false)[0];
JUnitConfiguration configuration = createConfiguration(testMethod);
ProcessOutput processOutput = doStartTestsProcess(configuration);
String testOutput = processOutput.out.toString();
assertEmpty(processOutput.err);
switch (myJUnitVersion) {
case "4.4": case "4.5": break; //shouldn't work for old versions
default:
assertTrue(testOutput, testOutput.contains("Test1"));
}
}
@@ -20,6 +20,7 @@ import com.intellij.execution.configurations.RunConfiguration;
import com.intellij.execution.junit.JUnitConfiguration;
import com.intellij.idea.Bombed;
import com.intellij.idea.IdeaTestApplication;
import com.intellij.java.execution.AbstractTestFrameworkCompilingIntegrationTest;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.vfs.VfsUtilCore;
@@ -34,19 +35,27 @@ import jetbrains.buildServer.messages.serviceMessages.TestFailed;
import jetbrains.buildServer.messages.serviceMessages.TestIgnored;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.idea.maven.aether.ArtifactRepositoryManager;
import org.jetbrains.jps.model.library.JpsMavenRepositoryLibraryDescriptor;
import java.util.Calendar;
import java.util.List;
import java.util.stream.Collectors;
public class JUnit5IntegrationTest extends JUnitAbstractCompilingIntegrationTest {
public class JUnit5IntegrationTest extends AbstractTestFrameworkCompilingIntegrationTest {
@Override
protected String getTestContentRoot() {
return VfsUtilCore.pathToUrl(PlatformTestUtil.getCommunityPath() + "/plugins/junit5_rt_tests/testData/integration/mixed45Project");
}
@Override
protected void setupLibraries() throws Exception {
final ArtifactRepositoryManager repoManager = getRepoManager();
addLibs(myModule, new JpsMavenRepositoryLibraryDescriptor("org.junit.jupiter", "junit-jupiter-api", "5.1.0"), repoManager);
addLibs(myModule, new JpsMavenRepositoryLibraryDescriptor("junit", "junit", "4.12"), repoManager);
}
public void testRunPackage() throws Exception {
RunConfiguration configuration = createRunPackageConfiguration("mixed");
ProcessOutput processOutput = doStartTestsProcess(configuration);
@@ -222,12 +231,4 @@ public class JUnit5IntegrationTest extends JUnitAbstractCompilingIntegrationTest
assertInstanceOf(configuration, JUnitConfiguration.class);
return configuration;
}
@Override
protected JpsMavenRepositoryLibraryDescriptor[] getRequiredLibs() {
return new JpsMavenRepositoryLibraryDescriptor[] {
new JpsMavenRepositoryLibraryDescriptor("org.junit.jupiter", "junit-jupiter-api", "5.1.0"),
new JpsMavenRepositoryLibraryDescriptor("junit", "junit", "4.12")
};
}
}
@@ -8,7 +8,7 @@ import com.intellij.execution.junit.JUnitConfiguration;
import com.intellij.execution.testDiscovery.TestDiscoveryDataSocketListener;
import com.intellij.execution.testDiscovery.TestDiscoveryExtension;
import com.intellij.execution.testDiscovery.TestDiscoveryIndex;
import com.intellij.junit4.JUnitAbstractIntegrationTest;
import com.intellij.java.execution.AbstractTestFrameworkIntegrationTest;
import com.intellij.openapi.actionSystem.LangDataKeys;
import com.intellij.openapi.compiler.CompilerMessage;
import com.intellij.openapi.compiler.CompilerMessageCategory;
@@ -27,14 +27,13 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.jps.model.library.JpsMavenRepositoryLibraryDescriptor;
import java.io.IOException;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
// TODO parametrize by 1) junit version 2) TD protocol
// TODO get agent from sources
public class TestDiscoveryJUnitIntegrationTest extends JUnitAbstractIntegrationTest {
public class TestDiscoveryJUnitIntegrationTest extends AbstractTestFrameworkIntegrationTest {
private static final String myJUnitVersion = "4.12";
private CompilerTester myCompilerTester;
@@ -104,7 +104,7 @@ public class TestNGConfiguration extends JavaTestConfigurationBase {
return null;
}
public RunProfileState getState(@NotNull final Executor executor, @NotNull final ExecutionEnvironment env) {
public TestNGRunnableState getState(@NotNull final Executor executor, @NotNull final ExecutionEnvironment env) {
final TestData data = getPersistantData();
if (data.TEST_OBJECT.equals(TestType.SOURCE.getType()) || data.getChangeList() != null) {
return new TestNGTestDiscoveryRunnableState(env, this);
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="true" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="intellij.java.tests" scope="TEST" />
<orderEntry type="module" module-name="intellij.platform.testFramework" scope="TEST" />
<orderEntry type="module" module-name="intellij.java.testFramework" scope="TEST" />
<orderEntry type="module" module-name="intellij.testng" scope="TEST" />
<orderEntry type="module" module-name="intellij.java.execution.impl" scope="TEST" />
<orderEntry type="module" module-name="intellij.java.aetherDependencyResolver" scope="TEST" />
</component>
</module>
@@ -0,0 +1,88 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.testng.integration;
import com.intellij.execution.ExecutionException;
import com.intellij.java.execution.AbstractTestFrameworkCompilingIntegrationTest;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiMethod;
import com.intellij.testFramework.EdtRule;
import com.intellij.testFramework.PlatformTestUtil;
import com.intellij.testFramework.RunsInEdt;
import com.theoryinpractice.testng.configuration.TestNGConfiguration;
import org.jetbrains.jps.model.library.JpsMavenRepositoryLibraryDescriptor;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import java.util.Arrays;
import java.util.Collection;
@RunsInEdt
@RunWith(Parameterized.class)
public class TestNGIntegrationTest extends AbstractTestFrameworkCompilingIntegrationTest {
@Rule public final EdtRule edtRule = new EdtRule();
@Rule public final TestName myNameRule = new TestName();
@Parameterized.Parameter
public String myTestNGVersion;
@Parameterized.Parameters(name = "{0}")
public static Collection<Object[]> data() {
return Arrays.asList(
createParams("6.8"),
createParams("6.11"),
createParams("6.10"),
createParams("6.13.1"),
createParams("6.14.2")
);
}
private static Object[] createParams(final String version) {
return new Object[]{version};
}
@Override
protected void setupLibraries() throws Exception {
addLibs(myModule, new JpsMavenRepositoryLibraryDescriptor("org.testng", "testng", myTestNGVersion), getRepoManager());
}
@Override
protected String getTestContentRoot() {
String methodName = myNameRule.getMethodName();
methodName = methodName.substring(0, methodName.indexOf("["));
return VfsUtilCore.pathToUrl(PlatformTestUtil.getCommunityPath() + "/plugins/testng_rt/tests/testData/integration/" + methodName);
}
@Before
public void before() throws Exception {
setUp();
}
@After
public void after() throws Exception {
tearDown();
}
@Override
public String getName() {
return myNameRule.getMethodName();
}
@Test
public void simpleStart() throws ExecutionException {
PsiClass psiClass = findClass(myModule, "a.Test1");
assertNotNull(psiClass);
PsiMethod testMethod = psiClass.findMethodsByName("simple", false)[0];
TestNGConfiguration configuration = createConfiguration(testMethod);
ProcessOutput processOutput = doStartTestsProcess(configuration);
String testOutput = processOutput.out.toString();
assertEmpty(processOutput.err);
assertTrue(testOutput, testOutput.contains("sample output"));
}
}
@@ -0,0 +1,8 @@
package a;
public class Test1 {
@org.testng.annotations.Test
public void simple() {
System.out.println("sample output");
}
}