Search in sources :

Example 1 with AndroidJUnitConfiguration

use of com.android.tools.idea.testartifacts.junit.AndroidJUnitConfiguration in project android by JetBrains.

the class AndroidTestAndJUnitConfigurationConflictsTest method checkClassesInAllInPackage.

private void checkClassesInAllInPackage(TestSearchScope type) throws CantRunException {
    Module module = ModuleManager.getInstance(myFixture.getProject()).findModuleByName("app");
    assertNotNull(module);
    AndroidJUnitConfiguration configuration = createConfiguration(getProject(), "google.simpleapplication", module);
    configuration.getPersistentData().setScope(type);
    AndroidTestPackage testPackage = new AndroidTestPackage(configuration, ExecutionEnvironmentBuilder.create(DefaultRunExecutor.getRunExecutorInstance(), configuration).build());
    Set<PsiClass> myClasses = new HashSet<>();
    ConfigurationUtil.findAllTestClasses(testPackage.getClassFilter(configuration.getPersistentData()), null, myClasses);
    assertSize(1, myClasses);
    TestArtifactSearchScopes scopes = TestArtifactSearchScopes.get(module);
    assertNotNull(scopes);
    assertTrue(scopes.isUnitTestSource(myClasses.iterator().next().getContainingFile().getVirtualFile()));
}
Also used : TestArtifactSearchScopes(com.android.tools.idea.testartifacts.scopes.TestArtifactSearchScopes) PsiClass(com.intellij.psi.PsiClass) AndroidTestPackage(com.android.tools.idea.testartifacts.junit.AndroidTestPackage) AndroidJUnitConfiguration(com.android.tools.idea.testartifacts.junit.AndroidJUnitConfiguration) Module(com.intellij.openapi.module.Module) HashSet(java.util.HashSet)

Example 2 with AndroidJUnitConfiguration

use of com.android.tools.idea.testartifacts.junit.AndroidJUnitConfiguration in project android by JetBrains.

the class AndroidTestAndJUnitConfigurationConflictsTest method createConfiguration.

private static AndroidJUnitConfiguration createConfiguration(@NotNull Project project, @NotNull String packageQualifiedName, @NotNull Module module) {
    AndroidJUnitConfiguration configuration = new AndroidJUnitConfiguration("", project, AndroidJUnitConfigurationType.getInstance().getConfigurationFactories()[0]);
    configuration.getPersistentData().TEST_OBJECT = JUnitConfiguration.TEST_PACKAGE;
    configuration.getPersistentData().PACKAGE_NAME = packageQualifiedName;
    configuration.getPersistentData().setScope(TestSearchScope.WHOLE_PROJECT);
    configuration.setModule(module);
    return configuration;
}
Also used : AndroidJUnitConfiguration(com.android.tools.idea.testartifacts.junit.AndroidJUnitConfiguration)

Example 3 with AndroidJUnitConfiguration

use of com.android.tools.idea.testartifacts.junit.AndroidJUnitConfiguration in project android by JetBrains.

the class AndroidTestAndJUnitConfigurationConflictsTest method testDoubleClickRedirection.

public void testDoubleClickRedirection() throws Exception {
    String commonTestClassName = "google.testartifacts.ExampleTest";
    loadProject(TEST_ARTIFACTS_SAME_NAME_CLASSES);
    Executor executor = DefaultRunExecutor.getRunExecutorInstance();
    RunConfiguration jUnitConfiguration = createJUnitConfigurationFromDirectory(getProject(), "app/src/test/java");
    RunConfiguration androidTestRunConfiguration = createAndroidTestConfigurationFromDirectory(getProject(), "app/src/androidTest/java");
    assertNotNull(jUnitConfiguration);
    assertNotNull(androidTestRunConfiguration);
    SMTRunnerConsoleProperties jUnitProperties = ((AndroidJUnitConfiguration) jUnitConfiguration).createTestConsoleProperties(executor);
    SMTRunnerConsoleProperties androidTestProperties = new AndroidTestConsoleProperties(androidTestRunConfiguration, executor);
    PsiClass[] jUnitClasses = JavaPsiFacade.getInstance(getProject()).findClasses(commonTestClassName, jUnitProperties.getScope());
    PsiClass[] aTestClasses = JavaPsiFacade.getInstance(getProject()).findClasses(commonTestClassName, androidTestProperties.getScope());
    assertSize(1, jUnitClasses);
    assertSize(1, aTestClasses);
    assertNotSame(jUnitClasses[0], aTestClasses[0]);
}
Also used : AndroidTestConsoleProperties(com.android.tools.idea.testartifacts.instrumented.AndroidTestConsoleProperties) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) Executor(com.intellij.execution.Executor) AndroidTestRunConfiguration(com.android.tools.idea.testartifacts.instrumented.AndroidTestRunConfiguration) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) PsiClass(com.intellij.psi.PsiClass) AndroidJUnitConfiguration(com.android.tools.idea.testartifacts.junit.AndroidJUnitConfiguration) SMTRunnerConsoleProperties(com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties)

Example 4 with AndroidJUnitConfiguration

use of com.android.tools.idea.testartifacts.junit.AndroidJUnitConfiguration in project android by JetBrains.

the class TestConfigurationTesting method createConfigurationFromPsiElement.

@Nullable
private static RunConfiguration createConfigurationFromPsiElement(@NotNull Project project, @NotNull PsiElement psiElement) {
    ConfigurationContext context = createContext(project, psiElement);
    RunnerAndConfigurationSettings settings = context.getConfiguration();
    if (settings == null) {
        return null;
    }
    RunConfiguration configuration = settings.getConfiguration();
    if (configuration instanceof AndroidTestRunConfiguration || configuration instanceof AndroidJUnitConfiguration) {
        return configuration;
    }
    return null;
}
Also used : ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) AndroidTestRunConfiguration(com.android.tools.idea.testartifacts.instrumented.AndroidTestRunConfiguration) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) AndroidTestRunConfiguration(com.android.tools.idea.testartifacts.instrumented.AndroidTestRunConfiguration) AndroidJUnitConfiguration(com.android.tools.idea.testartifacts.junit.AndroidJUnitConfiguration) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with AndroidJUnitConfiguration

use of com.android.tools.idea.testartifacts.junit.AndroidJUnitConfiguration in project android by JetBrains.

the class PostSyncProjectSetupTest method testJUnitRunConfigurationSetup.

public void testJUnitRunConfigurationSetup() {
    when(myIdeInfo.isAndroidStudio()).thenReturn(true);
    PostSyncProjectSetup.Request request = new PostSyncProjectSetup.Request();
    mySetup.setUpProject(request, myProgressIndicator);
    ConfigurationFactory configurationFactory = AndroidJUnitConfigurationType.getInstance().getConfigurationFactories()[0];
    AndroidJUnitConfiguration jUnitConfiguration = new AndroidJUnitConfiguration("", getProject(), configurationFactory);
    myRunManager.addConfiguration(myRunManager.createConfiguration(jUnitConfiguration, configurationFactory), true);
    List<RunConfiguration> junitRunConfigurations = myRunManager.getConfigurationsList(AndroidJUnitConfigurationType.getInstance());
    for (RunConfiguration runConfiguration : junitRunConfigurations) {
        assertSize(1, myRunManager.getBeforeRunTasks(runConfiguration));
        assertEquals(MakeBeforeRunTaskProvider.ID, myRunManager.getBeforeRunTasks(runConfiguration).get(0).getProviderId());
    }
    RunConfiguration runConfiguration = junitRunConfigurations.get(0);
    List<BeforeRunTask> tasks = new LinkedList<>(myRunManager.getBeforeRunTasks(runConfiguration));
    BeforeRunTask newTask = new MakeBeforeRunTaskProvider(getProject()).createTask(runConfiguration);
    newTask.setEnabled(true);
    tasks.add(newTask);
    myRunManager.setBeforeRunTasks(runConfiguration, tasks, false);
    mySetup.setUpProject(request, myProgressIndicator);
    assertSize(2, myRunManager.getBeforeRunTasks(runConfiguration));
}
Also used : BeforeRunTask(com.intellij.execution.BeforeRunTask) MakeBeforeRunTaskProvider(com.android.tools.idea.gradle.run.MakeBeforeRunTaskProvider) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory) AndroidJUnitConfiguration(com.android.tools.idea.testartifacts.junit.AndroidJUnitConfiguration) LinkedList(java.util.LinkedList)

Aggregations

AndroidJUnitConfiguration (com.android.tools.idea.testartifacts.junit.AndroidJUnitConfiguration)5 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)3 AndroidTestRunConfiguration (com.android.tools.idea.testartifacts.instrumented.AndroidTestRunConfiguration)2 PsiClass (com.intellij.psi.PsiClass)2 MakeBeforeRunTaskProvider (com.android.tools.idea.gradle.run.MakeBeforeRunTaskProvider)1 AndroidTestConsoleProperties (com.android.tools.idea.testartifacts.instrumented.AndroidTestConsoleProperties)1 AndroidTestPackage (com.android.tools.idea.testartifacts.junit.AndroidTestPackage)1 TestArtifactSearchScopes (com.android.tools.idea.testartifacts.scopes.TestArtifactSearchScopes)1 BeforeRunTask (com.intellij.execution.BeforeRunTask)1 Executor (com.intellij.execution.Executor)1 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)1 ConfigurationContext (com.intellij.execution.actions.ConfigurationContext)1 ConfigurationFactory (com.intellij.execution.configurations.ConfigurationFactory)1 DefaultRunExecutor (com.intellij.execution.executors.DefaultRunExecutor)1 SMTRunnerConsoleProperties (com.intellij.execution.testframework.sm.runner.SMTRunnerConsoleProperties)1 Module (com.intellij.openapi.module.Module)1 HashSet (java.util.HashSet)1 LinkedList (java.util.LinkedList)1 Nullable (org.jetbrains.annotations.Nullable)1