Search in sources :

Example 1 with JUnitConfiguration

use of com.intellij.execution.junit.JUnitConfiguration in project intellij-community by JetBrains.

the class JUnit4IntegrationTest method ignoredTestMethod.

@Test
public void ignoredTestMethod() throws Throwable {
    EdtTestUtil.runInEdtAndWait(() -> {
        PsiClass psiClass = findClass(getModule1(), CLASS_NAME);
        assertNotNull(psiClass);
        PsiMethod testMethod = psiClass.findMethodsByName(METHOD_NAME, false)[0];
        JUnitConfiguration configuration = createConfiguration(testMethod);
        Executor executor = DefaultRunExecutor.getRunExecutorInstance();
        RunnerAndConfigurationSettingsImpl settings = new RunnerAndConfigurationSettingsImpl(RunManagerImpl.getInstanceImpl(getProject()), configuration, false);
        ExecutionEnvironment environment = new ExecutionEnvironment(executor, ProgramRunnerUtil.getRunner(DefaultRunExecutor.EXECUTOR_ID, settings), settings, getProject());
        TestObject state = configuration.getState(executor, environment);
        JavaParameters parameters = state.getJavaParameters();
        parameters.setUseDynamicClasspath(getProject());
        GeneralCommandLine commandLine = parameters.toCommandLine();
        StringBuffer buf = new StringBuffer();
        StringBuffer err = new StringBuffer();
        OSProcessHandler process = new OSProcessHandler(commandLine);
        process.addProcessListener(new ProcessAdapter() {

            @Override
            public void onTextAvailable(ProcessEvent event, Key outputType) {
                String text = event.getText();
                try {
                    if (outputType == ProcessOutputTypes.STDOUT && !text.isEmpty() && ServiceMessage.parse(text.trim()) == null) {
                        buf.append(text);
                    }
                    if (outputType == ProcessOutputTypes.STDERR) {
                        err.append(text);
                    }
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        });
        process.startNotify();
        process.waitFor();
        process.destroyProcess();
        String testOutput = buf.toString();
        assertEmpty(err.toString());
        switch(myJUnitVersion) {
            //shouldn't work for old versions
            case "4.4":
            //shouldn't work for old versions
            case "4.5":
                break;
            default:
                assertTrue(testOutput, testOutput.contains("Test1"));
        }
    });
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) PsiMethod(com.intellij.psi.PsiMethod) ProcessEvent(com.intellij.execution.process.ProcessEvent) JUnitConfiguration(com.intellij.execution.junit.JUnitConfiguration) PsiClass(com.intellij.psi.PsiClass) TestObject(com.intellij.execution.junit.TestObject) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) Executor(com.intellij.execution.Executor) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) RunnerAndConfigurationSettingsImpl(com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl) JavaParameters(com.intellij.execution.configurations.JavaParameters) ParseException(java.text.ParseException) Key(com.intellij.openapi.util.Key) Test(org.junit.Test)

Example 2 with JUnitConfiguration

use of com.intellij.execution.junit.JUnitConfiguration in project intellij-community by JetBrains.

the class ConfigurationRefactoringsTest method testRenameJUnitPackage.

public void testRenameJUnitPackage() throws IOException {
    PsiPackage psiPackage = mySource.createPackage("pkg");
    JUnitConfiguration configuration = createJUnitConfiguration(psiPackage, AllInPackageConfigurationProducer.class, new MapDataContext());
    rename(psiPackage, "pkg2");
    checkPackage("pkg2", configuration);
    PsiPackage outer = mySource.createPackage("outerPkg");
    move(JavaPsiFacade.getInstance(myProject).findPackage("pkg2"), outer.getQualifiedName());
    checkPackage("outerPkg.pkg2", configuration);
    rename(outer, "outer2");
    checkPackage("outer2.pkg2", configuration);
}
Also used : MapDataContext(com.intellij.testFramework.MapDataContext) JUnitConfiguration(com.intellij.execution.junit.JUnitConfiguration)

Example 3 with JUnitConfiguration

use of com.intellij.execution.junit.JUnitConfiguration in project intellij-community by JetBrains.

the class ConfigurationRefactoringsTest method testRenameBadTestClass.

public void testRenameBadTestClass() throws IOException {
    PsiClass psiClass = mySource.createClass("NotATest", NOT_A_TEST);
    assertNotNull(psiClass);
    JUnitConfigurationType instance = JUnitConfigurationType.getInstance();
    assertNotNull(instance);
    JUnitConfiguration configuration = new JUnitConfiguration("notATest", myProject, instance.getConfigurationFactories()[0]);
    configuration.setMainClass(psiClass);
    configuration.setModule(configuration.getValidModules().iterator().next());
    checkConfigurationException("NotATest isn't test class", configuration);
    RunManagerEx.getInstanceEx(myProject).setTemporaryConfiguration(new RunnerAndConfigurationSettingsImpl(null, configuration, false));
    rename(psiClass, "NotATest2");
    JUnitConfiguration.Data data = configuration.getPersistentData();
    assertEquals("NotATest2", data.getMainClassName());
    data.METHOD_NAME = "test";
    data.TEST_OBJECT = JUnitConfiguration.TEST_METHOD;
    checkConfigurationException("Test method 'test' doesn't exist", configuration);
    rename(psiClass.findMethodsByName("test", false)[0], "test2");
    assertEquals("NotATest2", data.getMainClassName());
    assertEquals("test2", data.getMethodName());
}
Also used : JUnitConfiguration(com.intellij.execution.junit.JUnitConfiguration) RunnerAndConfigurationSettingsImpl(com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl) JUnitConfigurationType(com.intellij.execution.junit.JUnitConfigurationType)

Example 4 with JUnitConfiguration

use of com.intellij.execution.junit.JUnitConfiguration in project intellij-community by JetBrains.

the class ConfigurationRefactoringsTest method testRefactorOtherClass.

public void testRefactorOtherClass() throws IOException {
    PsiClass psiClass = mySource.createClass("ATest", TEST_CODE);
    assertNotNull(psiClass);
    JUnitConfiguration configuration = createConfiguration(psiClass);
    psiClass = mySource.createClass("Application", APPLICATION_CODE);
    assertNotNull(psiClass);
    rename(psiClass, "NewName");
    checkClassName("ATest", configuration);
    mySource.createPackage("pkg");
    psiClass = mySource.findClass("NewName");
    assertNotNull(psiClass);
    move(psiClass, "pkg");
    checkClassName("ATest", configuration);
}
Also used : JUnitConfiguration(com.intellij.execution.junit.JUnitConfiguration)

Example 5 with JUnitConfiguration

use of com.intellij.execution.junit.JUnitConfiguration in project intellij-community by JetBrains.

the class ConfigurationRefactoringsTest method testRefactorTestMethod.

public void testRefactorTestMethod() throws IOException {
    PsiClass psiClass = mySource.createClass("ATest", TEST_CODE);
    assertNotNull(psiClass);
    PsiMethod testMethod = psiClass.findMethodsByName("test", false)[0];
    JUnitConfiguration configuration = createConfiguration(testMethod);
    rename(testMethod, "test1");
    checkMethodName("test1", configuration);
    checkClassName("ATest", configuration);
    assertEquals("ATest.test1", configuration.getName());
    move(psiClass, "pkg");
    checkClassName("pkg.ATest", configuration);
    psiClass = configuration.getConfigurationModule().findClass(configuration.getPersistentData().getMainClassName());
    rename(psiClass, "TestClassName");
    assertEquals("TestClassName.test1", configuration.getName());
    psiClass = configuration.getConfigurationModule().findClass(configuration.getPersistentData().getMainClassName());
    PsiClass otherTest = mySource.createClass("ATest", TEST_CODE);
    HashSet<PsiMember> members = new HashSet<>();
    assertNotNull(psiClass);
    members.add(psiClass.findMethodsByName("test1", false)[0]);
    moveMembers(otherTest, members);
    psiClass = configuration.getConfigurationModule().findClass(configuration.getPersistentData().getMainClassName());
    checkMethodName("test1", configuration);
    checkClassName("ATest", configuration);
    assertEquals("ATest.test1", configuration.getName());
    assertNotNull(psiClass);
    PsiMethod otherMethod = psiClass.findMethodsByName("otherMethod", false)[0];
    rename(otherMethod, "newName");
    checkMethodName("test1", configuration);
}
Also used : JUnitConfiguration(com.intellij.execution.junit.JUnitConfiguration) HashSet(com.intellij.util.containers.HashSet)

Aggregations

JUnitConfiguration (com.intellij.execution.junit.JUnitConfiguration)13 Module (com.intellij.openapi.module.Module)4 RunnerAndConfigurationSettingsImpl (com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl)3 TestArtifactSearchScopes (com.android.tools.idea.testartifacts.scopes.TestArtifactSearchScopes)2 Executor (com.intellij.execution.Executor)2 TestClassFilter (com.intellij.execution.junit.TestClassFilter)2 TestObject (com.intellij.execution.junit.TestObject)2 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)2 VisibleForTesting (com.android.annotations.VisibleForTesting)1 Location (com.intellij.execution.Location)1 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)1 ConfigurationFromContext (com.intellij.execution.actions.ConfigurationFromContext)1 RunConfigurationProducer (com.intellij.execution.actions.RunConfigurationProducer)1 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)1 JavaParameters (com.intellij.execution.configurations.JavaParameters)1 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)1 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)1 JUnitConfigurationType (com.intellij.execution.junit.JUnitConfigurationType)1 PatternConfigurationProducer (com.intellij.execution.junit.PatternConfigurationProducer)1