Search in sources :

Example 6 with BlazeInstrumentationTestApkBuildStep

use of com.google.idea.blaze.android.run.runner.BlazeInstrumentationTestApkBuildStep in project intellij by bazelbuild.

the class BlazeInstrumentationTestApkBuildStepIntegrationTest method nullExecRoot.

@Test
public void nullExecRoot() throws GetDeployInfoException, ApkProvisionException, GetArtifactsException {
    setupProject();
    Label testTarget = Label.create("//java/com/foo/app:instrumentation_test");
    Label instrumentorTarget = Label.create("//java/com/foo/app:test_app");
    Label appTarget = Label.create("//java/com/foo/app:app");
    ImmutableList<String> blazeFlags = ImmutableList.of("some_blaze_flag", "some_other_flag");
    MessageCollector messageCollector = new MessageCollector();
    BlazeContext context = BlazeContext.create();
    context.addOutputSink(IssueOutput.class, messageCollector);
    // Return null execroot
    when(mockBuildResultHelper.getBuildOutput()).thenReturn(new ParsedBepOutput(null, null, null, null, 0, BuildResult.SUCCESS, 0));
    // Setup interceptor for fake running of blaze commands and capture details.
    ExternalTaskInterceptor externalTaskInterceptor = new ExternalTaskInterceptor();
    registerApplicationService(ExternalTaskProvider.class, externalTaskInterceptor);
    // Return fake deploy info proto and mocked deploy info data object.
    BlazeApkDeployInfoProtoHelper helper = mock(BlazeApkDeployInfoProtoHelper.class);
    AndroidDeployInfo fakeInstrumentorProto = AndroidDeployInfo.newBuilder().build();
    AndroidDeployInfo fakeAppProto = AndroidDeployInfo.newBuilder().build();
    BlazeAndroidDeployInfo mockDeployInfo = mock(BlazeAndroidDeployInfo.class);
    when(helper.readDeployInfoProtoForTarget(eq(instrumentorTarget), any(BuildResultHelper.class), any())).thenReturn(fakeInstrumentorProto);
    when(helper.readDeployInfoProtoForTarget(eq(appTarget), any(BuildResultHelper.class), any())).thenReturn(fakeAppProto);
    when(helper.extractInstrumentationTestDeployInfoAndInvalidateManifests(eq(getProject()), eq(new File(getExecRoot())), eq(fakeInstrumentorProto), eq(fakeAppProto))).thenReturn(mockDeployInfo);
    // Perform
    BlazeInstrumentationTestApkBuildStep buildStep = new BlazeInstrumentationTestApkBuildStep(getProject(), testTarget, blazeFlags, helper);
    buildStep.build(context, new DeviceSession(null, null, null));
    // Verify
    assertThat(context.hasErrors()).isTrue();
    assertThat(messageCollector.getMessages()).contains("Could not locate execroot!");
}
Also used : AndroidDeployInfo(com.google.devtools.build.lib.rules.android.deployinfo.AndroidDeployInfoOuterClass.AndroidDeployInfo) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) DeviceSession(com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector.DeviceSession) Label(com.google.idea.blaze.base.model.primitives.Label) BlazeInstrumentationTestApkBuildStep(com.google.idea.blaze.android.run.runner.BlazeInstrumentationTestApkBuildStep) ParsedBepOutput(com.google.idea.blaze.base.command.buildresult.ParsedBepOutput) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) BlazeApkDeployInfoProtoHelper(com.google.idea.blaze.android.run.deployinfo.BlazeApkDeployInfoProtoHelper) MessageCollector(com.google.idea.blaze.android.MessageCollector) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) File(java.io.File) Test(org.junit.Test)

Example 7 with BlazeInstrumentationTestApkBuildStep

use of com.google.idea.blaze.android.run.runner.BlazeInstrumentationTestApkBuildStep in project intellij by bazelbuild.

the class BlazeInstrumentationTestApkBuildStepIntegrationTest method noTestAppSpecified.

@Test
public void noTestAppSpecified() {
    setProjectView("directories:", "  java/com/foo/app", "targets:", "  //java/com/foo/app:instrumentation_test", "android_sdk_platform: android-27");
    MockSdkUtil.registerSdk(workspace, "27");
    workspace.createFile(new WorkspacePath("java/com/foo/app/MainActivity.java"), "package com.foo.app", "import android.app.Activity;", "public class MainActivity extends Activity {}");
    workspace.createFile(new WorkspacePath("java/com/foo/app/Test.java"), "package com.foo.app", "public class Test {}");
    setTargetMap(android_binary("//java/com/foo/app:app").src("MainActivity.java"), android_binary("//java/com/foo/app:test_app").setResourceJavaPackage("com.foo.app.androidtest").src("Test.java").instruments("//java/com/foo/app:app"), android_instrumentation_test("//java/com/foo/app:instrumentation_test"));
    runFullBlazeSyncWithNoIssues();
    MessageCollector messageCollector = new MessageCollector();
    BlazeContext context = BlazeContext.create();
    context.addOutputSink(IssueOutput.class, messageCollector);
    BlazeInstrumentationTestApkBuildStep buildStep = new BlazeInstrumentationTestApkBuildStep(getProject(), Label.create("//java/com/foo/app:instrumentation_test"), ImmutableList.of());
    InstrumentorToTarget pair = buildStep.getInstrumentorToTargetPair(context, BlazeProjectDataManager.getInstance(getProject()).getBlazeProjectData());
    assertThat(pair).isNull();
    assertThat(messageCollector.getMessages()).hasSize(1);
    assertThat(messageCollector.getMessages().get(0)).contains("No \"test_app\" in target definition for //java/com/foo/app:instrumentation_test.");
}
Also used : WorkspacePath(com.google.idea.blaze.base.model.primitives.WorkspacePath) BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) MessageCollector(com.google.idea.blaze.android.MessageCollector) BlazeInstrumentationTestApkBuildStep(com.google.idea.blaze.android.run.runner.BlazeInstrumentationTestApkBuildStep) InstrumentorToTarget(com.google.idea.blaze.android.run.runner.BlazeInstrumentationTestApkBuildStep.InstrumentorToTarget) Test(org.junit.Test)

Example 8 with BlazeInstrumentationTestApkBuildStep

use of com.google.idea.blaze.android.run.runner.BlazeInstrumentationTestApkBuildStep in project intellij by bazelbuild.

the class BlazeInstrumentationTestApkBuildStepIntegrationTest method deployInfoBuiltCorrectly.

@Test
public void deployInfoBuiltCorrectly() throws GetDeployInfoException, ApkProvisionException {
    setupProject();
    Label testTarget = Label.create("//java/com/foo/app:instrumentation_test");
    Label instrumentorTarget = Label.create("//java/com/foo/app:test_app");
    Label appTarget = Label.create("//java/com/foo/app:app");
    BlazeContext context = BlazeContext.create();
    ImmutableList<String> blazeFlags = ImmutableList.of("some_blaze_flag", "some_other_flag");
    // Setup interceptor for fake running of blaze commands and capture details.
    ExternalTaskInterceptor externalTaskInterceptor = new ExternalTaskInterceptor();
    registerApplicationService(ExternalTaskProvider.class, externalTaskInterceptor);
    // Return fake deploy info proto and mocked deploy info data object.
    BlazeApkDeployInfoProtoHelper helper = mock(BlazeApkDeployInfoProtoHelper.class);
    AndroidDeployInfo fakeInstrumentorProto = AndroidDeployInfo.newBuilder().build();
    AndroidDeployInfo fakeAppProto = AndroidDeployInfo.newBuilder().build();
    BlazeAndroidDeployInfo mockDeployInfo = mock(BlazeAndroidDeployInfo.class);
    when(helper.readDeployInfoProtoForTarget(eq(instrumentorTarget), any(BuildResultHelper.class), any())).thenReturn(fakeInstrumentorProto);
    when(helper.readDeployInfoProtoForTarget(eq(appTarget), any(BuildResultHelper.class), any())).thenReturn(fakeAppProto);
    when(helper.extractInstrumentationTestDeployInfoAndInvalidateManifests(eq(getProject()), eq(new File(getExecRoot())), eq(fakeInstrumentorProto), eq(fakeAppProto))).thenReturn(mockDeployInfo);
    // Perform
    BlazeInstrumentationTestApkBuildStep buildStep = new BlazeInstrumentationTestApkBuildStep(getProject(), testTarget, blazeFlags, helper);
    buildStep.build(context, new DeviceSession(null, null, null));
    // Verify
    assertThat(buildStep.getDeployInfo()).isNotNull();
    assertThat(buildStep.getDeployInfo()).isEqualTo(mockDeployInfo);
    assertThat(externalTaskInterceptor.context).isEqualTo(context);
    assertThat(externalTaskInterceptor.command).contains(instrumentorTarget.toString());
    assertThat(externalTaskInterceptor.command).contains(appTarget.toString());
    assertThat(externalTaskInterceptor.command).contains("--output_groups=+android_deploy_info");
    assertThat(externalTaskInterceptor.command).containsAllIn(blazeFlags);
}
Also used : BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) AndroidDeployInfo(com.google.devtools.build.lib.rules.android.deployinfo.AndroidDeployInfoOuterClass.AndroidDeployInfo) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) BuildResultHelper(com.google.idea.blaze.base.command.buildresult.BuildResultHelper) BlazeApkDeployInfoProtoHelper(com.google.idea.blaze.android.run.deployinfo.BlazeApkDeployInfoProtoHelper) DeviceSession(com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector.DeviceSession) Label(com.google.idea.blaze.base.model.primitives.Label) BlazeAndroidDeployInfo(com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo) BlazeInstrumentationTestApkBuildStep(com.google.idea.blaze.android.run.runner.BlazeInstrumentationTestApkBuildStep) File(java.io.File) Test(org.junit.Test)

Example 9 with BlazeInstrumentationTestApkBuildStep

use of com.google.idea.blaze.android.run.runner.BlazeInstrumentationTestApkBuildStep in project intellij by bazelbuild.

the class BlazeInstrumentationTestApkBuildStepIntegrationTest method findInstrumentorAndTestTargets.

@Test
public void findInstrumentorAndTestTargets() {
    setupProject();
    BlazeInstrumentationTestApkBuildStep buildStep = new BlazeInstrumentationTestApkBuildStep(getProject(), Label.create("//java/com/foo/app:instrumentation_test"), ImmutableList.of());
    InstrumentorToTarget pair = buildStep.getInstrumentorToTargetPair(BlazeContext.create(), BlazeProjectDataManager.getInstance(getProject()).getBlazeProjectData());
    assertThat(pair.instrumentor).isEqualTo(Label.create("//java/com/foo/app:test_app"));
    assertThat(pair.target).isEqualTo(Label.create("//java/com/foo/app:app"));
}
Also used : BlazeInstrumentationTestApkBuildStep(com.google.idea.blaze.android.run.runner.BlazeInstrumentationTestApkBuildStep) InstrumentorToTarget(com.google.idea.blaze.android.run.runner.BlazeInstrumentationTestApkBuildStep.InstrumentorToTarget) Test(org.junit.Test)

Aggregations

BlazeInstrumentationTestApkBuildStep (com.google.idea.blaze.android.run.runner.BlazeInstrumentationTestApkBuildStep)9 Test (org.junit.Test)9 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)8 MessageCollector (com.google.idea.blaze.android.MessageCollector)6 AndroidDeployInfo (com.google.devtools.build.lib.rules.android.deployinfo.AndroidDeployInfoOuterClass.AndroidDeployInfo)5 BlazeAndroidDeployInfo (com.google.idea.blaze.android.run.deployinfo.BlazeAndroidDeployInfo)5 BlazeApkDeployInfoProtoHelper (com.google.idea.blaze.android.run.deployinfo.BlazeApkDeployInfoProtoHelper)5 DeviceSession (com.google.idea.blaze.android.run.runner.BlazeAndroidDeviceSelector.DeviceSession)5 BuildResultHelper (com.google.idea.blaze.base.command.buildresult.BuildResultHelper)5 Label (com.google.idea.blaze.base.model.primitives.Label)5 InstrumentorToTarget (com.google.idea.blaze.android.run.runner.BlazeInstrumentationTestApkBuildStep.InstrumentorToTarget)4 File (java.io.File)4 GetDeployInfoException (com.google.idea.blaze.android.run.deployinfo.BlazeApkDeployInfoProtoHelper.GetDeployInfoException)1 ParsedBepOutput (com.google.idea.blaze.base.command.buildresult.ParsedBepOutput)1 WorkspacePath (com.google.idea.blaze.base.model.primitives.WorkspacePath)1