폴더블에서 앱 테스트

폴더블 기기에는 특수한 테스트가 필요한 고유한 기능이 있습니다. 큰 화면과 작은 화면의 폴더블에서 기기가 접힌 상태와 펼친 상태, 세로 및 가로 방향, 탁자 모드와 책 모드, 멀티 윈도우 모드로 앱을 테스트하세요. 자세한 내용은 대형 화면 앱 품질 가이드라인을 참고하세요.

FoldingFeature

Jetpack WindowManager 라이브러리는 폴더블 기기의 상태가 변경될 때 개발자가 앱의 레이아웃을 수정할 수 있도록 상태 변경을 앱에 알립니다.

window-testing 아티팩트에는 테스트에서 FoldingFeature를 시뮬레이션하는 맞춤 WindowInfoLayout을 게시할 수 있는 WindowLayoutInfoPublisherRule JUnit4 규칙이 포함되어 있습니다.

접기 기능의 상태를 테스트하려면 먼저 테스트 클래스와 테스트 규칙을 정의합니다.

Kotlin

import androidx.window.layout.FoldingFeature.Orientation.Companion.HORIZONTAL
import androidx.window.layout.FoldingFeature.Orientation.Companion.VERTICAL
import androidx.window.layout.FoldingFeature.State.Companion.FLAT
import androidx.window.layout.FoldingFeature.State.Companion.HALF_OPENED
import androidx.window.testing.layout.FoldingFeature
import androidx.window.testing.layout.TestWindowLayoutInfo
import androidx.window.testing.layout.WindowLayoutInfoPublisherRule

@RunWith(AndroidJUnit4::class)
class DisplayFeaturesActivityTest {
    private val activityRule = ActivityScenarioRule(DisplayFeaturesActivity::class.java)
    private val publisherRule = WindowLayoutInfoPublisherRule()

    @get:Rule
    val testRule: TestRule

    init {
        testRule = RuleChain.outerRule(publisherRule).around(activityRule)
    }

    @Test myTest() {
       // TODO
    }
}

자바

import static androidx.window.layout.FoldingFeature.Orientation.HORIZONTAL;
import static androidx.window.layout.FoldingFeature.Orientation.VERTICAL;
import static androidx.window.layout.FoldingFeature.State.FLAT;
import static androidx.window.layout.FoldingFeature.State.HALF_OPENED;
import static androidx.window.testing.layout.DisplayFeatureTesting.createFoldingFeature;
import static androidx.window.testing.layout.WindowLayoutInfoTesting.createWindowLayoutInfo;
import androidx.window.layout.FoldingFeature;
import androidx.window.layout.WindowLayoutInfo;
import androidx.window.testing.layout.WindowLayoutInfoPublisherRule;

@RunWith(AndroidJUnit4.class)
public class DisplayFeaturesActivityJavaTest {
    private WindowLayoutInfoPublisherRule publisherRule = new WindowLayoutInfoPublisherRule();

    @Rule public TestRule testRule;

    public DisplayFeaturesActivityJavaTest() {
        testRule = RuleChain.outerRule(publisherRule).around(activityRule);
    };

     @Test
     public void myTest() {
         // TODO
     }
}

다음으로, 너비를 0으로 하여 중앙에서 수평으로 접은 상태로 절반을 펼친 폴더블 화면과 같은 접기 기능을 시뮬레이션할 수 있습니다.

Kotlin

val feature = FoldingFeature(
                  activity = activity,
                  state = HALF_OPENED,
                  orientation = HORIZONTAL)

val expected = TestWindowLayoutInfo(listOf(feature))

자바

FoldingFeature feature = createFoldingFeature(
                             activity,
                             -1,
                             0,
                             HALF_OPENED,
                             HORIZONTAL);

WindowLayoutInfo expected = createWindowLayoutInfo(
                                Collections.singletonList(feature)
                            );

그런 다음 WindowLayoutInfoPublisherRule을 사용하여 맞춤 WindowLayoutInfo를 게시합니다.

Kotlin

@Test
myTest() {
    ...
    publisherRule.overrideWindowLayoutInfo(expected)
    ...
}

자바

@Test
public void myTest() {
    ...
    publisherRule.overrideWindowLayoutInfo(expected);
    ...
}

마지막으로, 사용 가능한 Espresso 매처를 사용하여 활동 레이아웃이 예상대로 작동하는지 확인합니다.

다음 예에서는 화면 중앙에 HALF_OPENED 수직 힌지가 있는 FoldingFeature를 시뮬레이션한 다음 매처를 사용하여 레이아웃이 예상대로 작동하는지 확인합니다.

Kotlin

@Test
fun testDeviceOpen_Vertical() {
    activityRule.scenario.onActivity { activity ->
        val feature = FoldingFeature(
                          activity = activity,
                          state = HALF_OPENED,
                          orientation = VERTICAL)
        val expected = TestWindowLayoutInfo(listOf(feature))
        publisherRule.overrideWindowLayoutInfo(expected)
    }

    // Checks that start_layout is on the left of end_layout with a vertical folding feature.
    onView(withId(R.id.start_layout))
        .check(isCompletelyLeftOf(withId(R.id.end_layout)))
}

자바

@Test
public void testDeviceOpen_Vertical() {
    activityRule
        .getScenario()
        .onActivity(
            activity -> {
                FoldingFeature feature = createFoldingFeature(
                                             activity,
                                             -1,
                                             0,
                                             HALF_OPENED,
                                             VERTICAL);

                WindowLayoutInfo expected = createWindowLayoutInfo(
                                                Collections.singletonList(feature)
                                            );

                publisherRule.overrideWindowLayoutInfo(expected);
            });

    // Checks that start_layout is on the left of end_layout with a vertical folding feature.
    onView(withId(R.id.start_layout))
        .check(isCompletelyLeftOf(withId(R.id.end_layout)));
}

구성 변경

앱이 onConfigurationChanged() 콜백 메서드를 사용하여 구성 변경을 프로그래매틱 방식으로 처리하는 경우, 앱이 구성 변경, 특히 세로 방향과 가로 방향 간의 기기 회전에 즉시 반응하는지 확인합니다.

앱이 방향 변경 및 디스플레이 크기 변경을 알 수 있도록 하려면 activity:configChanges 매니페스트 요소에서 다음 구성 설정을 지정합니다.

android:configChanges="orientation|screenLayout|screenSize|smallestScreenSize"

추가 리소스