Search in sources :

Example 1 with BuildVariantsToolWindowFixture

use of com.android.tools.idea.tests.gui.framework.fixture.BuildVariantsToolWindowFixture in project android by JetBrains.

the class BuildVariantsTest method testSwitchVariantWithFlavor.

@Ignore("failed in http://go/aj/job/studio-ui-test/389 and from IDEA")
@Test
public void testSwitchVariantWithFlavor() throws IOException {
    guiTest.importProjectAndWaitForProjectSyncToFinish("Flavoredlib");
    BuildVariantsToolWindowFixture buildVariants = guiTest.ideFrame().getBuildVariantsWindow();
    buildVariants.selectVariantForModule(MODULE_NAME, "flavor1Release");
    String generatedSourceDirPath = MODULE_NAME + "/build/generated/source/";
    Collection<String> sourceFolders = guiTest.ideFrame().getSourceFolderRelativePaths(MODULE_NAME, SOURCE);
    assertThat(sourceFolders).containsAllOf(generatedSourceDirPath + "r/flavor1/release", generatedSourceDirPath + "aidl/flavor1/release", generatedSourceDirPath + "buildConfig/flavor1/release", generatedSourceDirPath + "rs/flavor1/release", MODULE_NAME + "/src/flavor1Release/aidl", MODULE_NAME + "/src/flavor1Release/java", MODULE_NAME + "/src/flavor1Release/jni", MODULE_NAME + "/src/flavor1Release/rs");
    Module appModule = guiTest.ideFrame().getModule(MODULE_NAME);
    JpsAndroidModuleProperties androidFacetProperties = AndroidFacet.getInstance(appModule).getProperties();
    assertEquals("assembleFlavor1Release", androidFacetProperties.ASSEMBLE_TASK_NAME);
    // 'release' variant does not have the _android_test_ artifact.
    assertThat(androidFacetProperties.ASSEMBLE_TEST_TASK_NAME).isEmpty();
    buildVariants.selectVariantForModule(MODULE_NAME, "flavor1Debug");
    sourceFolders = guiTest.ideFrame().getSourceFolderRelativePaths(MODULE_NAME, SOURCE);
    assertThat(sourceFolders).containsAllOf(generatedSourceDirPath + "r/flavor1/debug", generatedSourceDirPath + "aidl/flavor1/debug", generatedSourceDirPath + "buildConfig/flavor1/debug", generatedSourceDirPath + "rs/flavor1/debug", MODULE_NAME + "/src/flavor1Debug/aidl", MODULE_NAME + "/src/flavor1Debug/java", MODULE_NAME + "/src/flavor1Debug/jni", MODULE_NAME + "/src/flavor1Debug/rs");
    assertEquals("assembleFlavor1Debug", androidFacetProperties.ASSEMBLE_TASK_NAME);
    // Verifies that https://code.google.com/p/android/issues/detail?id=83077 is not a bug.
    assertEquals("assembleFlavor1DebugAndroidTest", androidFacetProperties.ASSEMBLE_TEST_TASK_NAME);
}
Also used : JpsAndroidModuleProperties(org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties) Module(com.intellij.openapi.module.Module) BuildVariantsToolWindowFixture(com.android.tools.idea.tests.gui.framework.fixture.BuildVariantsToolWindowFixture) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with BuildVariantsToolWindowFixture

use of com.android.tools.idea.tests.gui.framework.fixture.BuildVariantsToolWindowFixture in project android by JetBrains.

the class BuildVariantsTest method doTestGeneratedFolders.

private void doTestGeneratedFolders(@NotNull String pluginVersion, @NotNull String gradleVersion) throws IOException {
    guiTest.importMultiModule();
    guiTest.ideFrame().updateAndroidGradlePluginVersion(pluginVersion);
    guiTest.ideFrame().updateGradleWrapperVersion(gradleVersion);
    // Add generated folders to all kinds of variants.
    File appBuildFile = new File(guiTest.ideFrame().getProjectPath(), join("app", SdkConstants.FN_BUILD_GRADLE));
    assertAbout(file()).that(appBuildFile).isFile();
    String gradleSnippet = "project.afterEvaluate {\n" + "  android.applicationVariants.all { variant ->\n" + "    if (variant.name != 'debug') return" + "\n" + "" + "    File sourceFolder = file(\"${buildDir}/generated/customCode/${variant.dirName}\")\n" + "    variant.addJavaSourceFoldersToModel(sourceFolder)\n" + "\n" + "    def androidTestVariant = variant.testVariant\n" + "    File androidTestSourceFolder = file(\"${buildDir}/generated/customCode/${androidTestVariant.dirName}\")\n" + "    androidTestVariant.addJavaSourceFoldersToModel(androidTestSourceFolder)\n";
    if (pluginVersion.startsWith("1.3")) {
        gradleSnippet += "\n" + "    def unitTestVariant = variant.unitTestVariant\n" + "    File unitTestSourceFolder = file(\"${buildDir}/generated/customCode/${unitTestVariant.dirName}\")\n" + "    unitTestVariant.addJavaSourceFoldersToModel(unitTestSourceFolder)\n";
    }
    gradleSnippet += "}\n}";
    appendToFile(appBuildFile, gradleSnippet);
    guiTest.ideFrame().requestProjectSync().waitForGradleProjectSyncToFinish();
    BuildVariantsToolWindowFixture buildVariants = guiTest.ideFrame().getBuildVariantsWindow();
    assertEquals("Android Instrumentation Tests", buildVariants.getSelectedTestArtifact());
    String generatedSourceDirPath = MODULE_NAME + "/build/generated/customCode/";
    String mainSrc = generatedSourceDirPath + "debug";
    String androidTestSrc = generatedSourceDirPath + "androidTest/debug";
    String unitTestSrc = generatedSourceDirPath + "test/debug";
    if (compareVersions(pluginVersion, "1.1") < 0) {
        // In 1.0, we used "test/debug" for android tests and there was no concept of unit testing.
        androidTestSrc = unitTestSrc;
        unitTestSrc = null;
    }
    Collection<String> sourceFolders = guiTest.ideFrame().getSourceFolderRelativePaths(MODULE_NAME, SOURCE);
    assertThat(sourceFolders).contains(mainSrc);
    assertThat(sourceFolders).containsNoneOf(androidTestSrc, unitTestSrc);
    Collection<String> testSourceFolders = guiTest.ideFrame().getSourceFolderRelativePaths(MODULE_NAME, TEST_SOURCE);
    assertThat(testSourceFolders).contains(androidTestSrc);
    assertThat(testSourceFolders).containsNoneOf(unitTestSrc, mainSrc);
    if (compareVersions(pluginVersion, "1.1") >= 0) {
        buildVariants.selectTestArtifact("Unit Tests");
        sourceFolders = guiTest.ideFrame().getSourceFolderRelativePaths(MODULE_NAME, SOURCE);
        assertThat(sourceFolders).contains(mainSrc);
        assertThat(sourceFolders).containsNoneOf(androidTestSrc, unitTestSrc);
        testSourceFolders = guiTest.ideFrame().getSourceFolderRelativePaths(MODULE_NAME, TEST_SOURCE);
        if (compareVersions(pluginVersion, "1.3") >= 0) {
            // In 1.3 we started to include unit testing generated folders in the model.
            assertThat(testSourceFolders).contains(unitTestSrc);
            assertThat(testSourceFolders).containsNoneOf(androidTestSrc, mainSrc);
        } else {
            assertThat(testSourceFolders).containsNoneOf(unitTestSrc, androidTestSrc, mainSrc);
        }
    }
}
Also used : FileUtil.appendToFile(com.intellij.openapi.util.io.FileUtil.appendToFile) File(java.io.File) BuildVariantsToolWindowFixture(com.android.tools.idea.tests.gui.framework.fixture.BuildVariantsToolWindowFixture)

Example 3 with BuildVariantsToolWindowFixture

use of com.android.tools.idea.tests.gui.framework.fixture.BuildVariantsToolWindowFixture in project android by JetBrains.

the class BuildVariantsTest method switchingTestArtifacts.

@Ignore("failed in http://go/aj/job/studio-ui-test/389 and from IDEA")
@Test
public void switchingTestArtifacts() throws IOException {
    guiTest.importProjectAndWaitForProjectSyncToFinish("SimpleApplication");
    BuildVariantsToolWindowFixture buildVariants = guiTest.ideFrame().getBuildVariantsWindow();
    assertEquals("Android Instrumentation Tests", buildVariants.getSelectedTestArtifact());
    String androidTestSrc = MODULE_NAME + "/src/androidTest/java";
    String unitTestSrc = MODULE_NAME + "/src/test/java";
    Collection<String> testSourceFolders = guiTest.ideFrame().getSourceFolderRelativePaths(MODULE_NAME, TEST_SOURCE);
    assertThat(testSourceFolders).contains(androidTestSrc);
    assertThat(testSourceFolders).doesNotContain(unitTestSrc);
    buildVariants.selectTestArtifact("Unit Tests");
    testSourceFolders = guiTest.ideFrame().getSourceFolderRelativePaths(MODULE_NAME, TEST_SOURCE);
    assertThat(testSourceFolders).contains(unitTestSrc);
    assertThat(testSourceFolders).doesNotContain(androidTestSrc);
}
Also used : BuildVariantsToolWindowFixture(com.android.tools.idea.tests.gui.framework.fixture.BuildVariantsToolWindowFixture) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

BuildVariantsToolWindowFixture (com.android.tools.idea.tests.gui.framework.fixture.BuildVariantsToolWindowFixture)3 Ignore (org.junit.Ignore)2 Test (org.junit.Test)2 Module (com.intellij.openapi.module.Module)1 FileUtil.appendToFile (com.intellij.openapi.util.io.FileUtil.appendToFile)1 File (java.io.File)1 JpsAndroidModuleProperties (org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties)1