diff --git a/binder/src/test/java/io/grpc/binder/internal/RobolectricBinderTransportTest.java b/binder/src/test/java/io/grpc/binder/internal/RobolectricBinderTransportTest.java new file mode 100644 index 0000000000..7d33606784 --- /dev/null +++ b/binder/src/test/java/io/grpc/binder/internal/RobolectricBinderTransportTest.java @@ -0,0 +1,137 @@ +/* + * Copyright 2025 The gRPC Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.grpc.binder.internal; + +import static org.robolectric.Shadows.shadowOf; + +import android.app.Application; +import android.content.Intent; +import androidx.test.core.app.ApplicationProvider; +import io.grpc.ServerStreamTracer; +import io.grpc.binder.AndroidComponentAddress; +import io.grpc.internal.AbstractTransportTest; +import io.grpc.internal.ClientTransportFactory.ClientTransportOptions; +import io.grpc.internal.GrpcUtil; +import io.grpc.internal.InternalServer; +import io.grpc.internal.ManagedClientTransport; +import io.grpc.internal.ObjectPool; +import io.grpc.internal.SharedResourcePool; +import java.util.List; +import java.util.concurrent.Executor; +import java.util.concurrent.ScheduledExecutorService; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.LooperMode; +import org.robolectric.annotation.LooperMode.Mode; + +/** + * All of the AbstractTransportTest cases applied to {@link BinderTransport} running in a + * Robolectric environment. + * + *
Runs much faster than BinderTransportTest and doesn't require an Android device/emulator. + * Somewhat less realistic but allows simulating behavior that would be difficult or impossible with + * real Android. + * + *
NB: Unlike most robolectric tests, we run in {@link LooperMode.Mode#INSTRUMENTATION_TEST},
+ * meaning test cases don't run on the main thread. This supports the AbstractTransportTest approach
+ * where the test thread frequently blocks waiting for transport state changes to take effect.
+ */
+@RunWith(RobolectricTestRunner.class)
+@LooperMode(Mode.INSTRUMENTATION_TEST)
+public final class RobolectricBinderTransportTest extends AbstractTransportTest {
+
+ private final Application application = ApplicationProvider.getApplicationContext();
+ private final ObjectPool