From 7043060204a89982b7215d5cf3abec23d5a37d12 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 2 Apr 2026 12:44:06 -0400 Subject: [PATCH] test: screenshot plain native view on UI thread in IsolatedTest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Uses @UiThreadTest to run entirely on the main thread — no runOnMainSync, no async waiting, no React Native. Validates the screenshot pipeline (ViewHelpers + Screenshot.snap) works deterministically. Co-Authored-By: Claude Sonnet 4.6 --- .../java/com/testapp/IsolatedTest.kt | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/android/app/src/androidTest/java/com/testapp/IsolatedTest.kt b/android/app/src/androidTest/java/com/testapp/IsolatedTest.kt index bcd300f..6996bf6 100644 --- a/android/app/src/androidTest/java/com/testapp/IsolatedTest.kt +++ b/android/app/src/androidTest/java/com/testapp/IsolatedTest.kt @@ -1,26 +1,27 @@ package com.rnstorybookautoscreenshots +import android.graphics.Color +import android.widget.TextView +import androidx.test.annotation.UiThreadTest import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.platform.app.InstrumentationRegistry -import com.testapp.MainApplication -import junit.framework.TestCase.assertNotNull -import junit.framework.TestCase.assertTrue +import com.facebook.testing.screenshot.Screenshot +import com.facebook.testing.screenshot.ViewHelpers import org.junit.Test import org.junit.runner.RunWith @RunWith(AndroidJUnit4::class) class IsolatedTest { - @Test - fun simpleTest() { - assertTrue(true) - } + @UiThreadTest @Test - fun constructViewTest() { + fun screenshotNativeView() { val context = InstrumentationRegistry.getInstrumentation().targetContext - val app = context.applicationContext as MainApplication - val surface = app.reactHost.createSurface(context, "SimpleTestComponent", null) - surface.start() - assertNotNull(surface.view) + val view = TextView(context).apply { + text = "Hello Screenshot" + setBackgroundColor(Color.WHITE) + } + ViewHelpers.setupView(view).setExactWidthPx(400).setExactHeightPx(100).layout() + Screenshot.snap(view).setName("native_view").record() } }