Search in sources :

Example 11 with JUnitConfiguration

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

the class RerunFailedTestsAction method getRunProfile.

@Override
protected MyRunProfile getRunProfile(@NotNull ExecutionEnvironment environment) {
    //noinspection ConstantConditions
    final JUnitConfiguration configuration = (JUnitConfiguration) myConsoleProperties.getConfiguration();
    final TestMethods testMethods = new TestMethods(configuration, environment, getFailedTests(configuration.getProject()));
    return new MyRunProfile(configuration) {

        @Override
        @NotNull
        public Module[] getModules() {
            return testMethods.getModulesToCompile();
        }

        @Override
        public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment env) {
            testMethods.clear();
            return testMethods;
        }
    };
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) Executor(com.intellij.execution.Executor) JUnitConfiguration(com.intellij.execution.junit.JUnitConfiguration) TestMethods(com.intellij.execution.junit.TestMethods) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with JUnitConfiguration

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

the class AndroidJUnitConfigurations method isFromContext.

// Copy of JUnitConfigurationProducer#isConfigurationFromContext using AndroidJUnitConfigurationType instead of JUnitConfigurationType
public static boolean isFromContext(@NotNull JUnitConfiguration unitConfiguration, @NotNull ConfigurationContext context, @NotNull ConfigurationFactory configurationFactory) {
    if (RunConfigurationProducer.getInstance(PatternConfigurationProducer.class).isMultipleElementsSelected(context)) {
        return false;
    }
    RunConfiguration predefinedConfiguration = context.getOriginalConfiguration(AndroidJUnitConfigurationType.getInstance());
    Location contextLocation = context.getLocation();
    String paramSetName = contextLocation instanceof PsiMemberParameterizedLocation ? ((PsiMemberParameterizedLocation) contextLocation).getParamSetName() : null;
    assert contextLocation != null;
    Location location = JavaExecutionUtil.stepIntoSingleClass(contextLocation);
    if (location == null) {
        return false;
    }
    PsiElement element = location.getPsiElement();
    PsiClass testClass = getTestClass(element);
    PsiMethod testMethod = getTestMethod(element, false);
    PsiPackage testPackage;
    if (element instanceof PsiPackage) {
        testPackage = (PsiPackage) element;
    } else {
        if (element instanceof PsiDirectory) {
            testPackage = JavaDirectoryService.getInstance().getPackage(((PsiDirectory) element));
        } else {
            testPackage = null;
        }
    }
    PsiDirectory testDir = element instanceof PsiDirectory ? (PsiDirectory) element : null;
    RunnerAndConfigurationSettings template = RunManager.getInstance(location.getProject()).getConfigurationTemplate(configurationFactory);
    Module predefinedModule = ((JUnitConfiguration) template.getConfiguration()).getConfigurationModule().getModule();
    String vmParameters = predefinedConfiguration instanceof JUnitConfiguration ? ((JUnitConfiguration) predefinedConfiguration).getVMParameters() : null;
    if (vmParameters != null && !Comparing.strEqual(vmParameters, unitConfiguration.getVMParameters())) {
        return false;
    }
    if (paramSetName != null && !Comparing.strEqual(paramSetName, unitConfiguration.getProgramParameters())) {
        return false;
    }
    TestObject testobject = unitConfiguration.getTestObject();
    if (testobject != null) {
        if (testobject.isConfiguredByElement(unitConfiguration, testClass, testMethod, testPackage, testDir)) {
            Module configurationModule = unitConfiguration.getConfigurationModule().getModule();
            if (Comparing.equal(location.getModule(), configurationModule)) {
                return true;
            }
            if (Comparing.equal(predefinedModule, configurationModule)) {
                return true;
            }
        }
    }
    return false;
}
Also used : PatternConfigurationProducer(com.intellij.execution.junit.PatternConfigurationProducer) JUnitConfiguration(com.intellij.execution.junit.JUnitConfiguration) TestObject(com.intellij.execution.junit.TestObject) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) Module(com.intellij.openapi.module.Module) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) Location(com.intellij.execution.Location)

Example 13 with JUnitConfiguration

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

the class AndroidTestPackage method getClassFilter.

@Override
@VisibleForTesting
public TestClassFilter getClassFilter(JUnitConfiguration.Data data) throws CantRunException {
    TestClassFilter classFilter = super.getClassFilter(data);
    JUnitConfiguration configuration = getConfiguration();
    Module[] modules = configuration instanceof AndroidJUnitConfiguration ? ((AndroidJUnitConfiguration) configuration).getModulesToCompile() : configuration.getModules();
    for (Module module : modules) {
        TestArtifactSearchScopes testArtifactSearchScopes = TestArtifactSearchScopes.get(module);
        if (testArtifactSearchScopes != null) {
            classFilter = classFilter.intersectionWith(testArtifactSearchScopes.getAndroidTestExcludeScope());
        }
    }
    return classFilter;
}
Also used : TestArtifactSearchScopes(com.android.tools.idea.testartifacts.scopes.TestArtifactSearchScopes) JUnitConfiguration(com.intellij.execution.junit.JUnitConfiguration) Module(com.intellij.openapi.module.Module) TestClassFilter(com.intellij.execution.junit.TestClassFilter) VisibleForTesting(com.android.annotations.VisibleForTesting)

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