Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f1dade40 authored by James Lemieux's avatar James Lemieux Committed by Fan Zhang
Browse files

Use binary resource support in robolectric

The resources available to tests are now exactly the merged resources
located in the APK under test.

Bug: 74359828
Test: make -j56 RunSettingsRoboTests
Change-Id: I050db81a92decefea23314b5ec7a62f77ff4bb2b
parent 1f5fab14
Loading
Loading
Loading
Loading
+67 −6
Original line number Diff line number Diff line
#############################################
# Settings Robolectric test target.         #
#############################################
LOCAL_PATH := $(call my-dir)

SETTINGS_AOSP_PATH := packages/apps/Settings

#############################################################
# Build SettingsTest.apk which includes test-only resources.#
#############################################################
include $(CLEAR_VARS)

LOCAL_PACKAGE_NAME := SettingsTest
LOCAL_PRIVATE_PLATFORM_APIS := true
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true
LOCAL_MODULE_TAGS := optional
LOCAL_USE_AAPT2 := true

RELATIVE_SETTINGS_AOSP_PATH := ../../../../../$(SETTINGS_AOSP_PATH)

LOCAL_MANIFEST_FILE := $(RELATIVE_SETTINGS_AOSP_PATH)/AndroidManifest.xml

LOCAL_SRC_FILES := $(call all-java-files-under, $(RELATIVE_SETTINGS_AOSP_PATH)/src)

LOCAL_RESOURCE_DIR += \
	$(LOCAL_PATH)/res \
	$(SETTINGS_AOSP_PATH)/res

LOCAL_STATIC_ANDROID_LIBRARIES := \
    androidx.slice_slice-builders \
    androidx.slice_slice-core \
    androidx.slice_slice-view \
    androidx.core_core \
    androidx.appcompat_appcompat \
    androidx.cardview_cardview \
    androidx.preference_preference \
    androidx.recyclerview_recyclerview \
    com.google.android.material_material \
    setupcompat \
    setupdesign

LOCAL_JAVA_LIBRARIES := \
    telephony-common \
    ims-common

LOCAL_STATIC_JAVA_LIBRARIES := \
    androidx.lifecycle_lifecycle-runtime \
    androidx.lifecycle_lifecycle-extensions \
    guava \
    jsr305 \
    settings-contextual-card-protos-lite \
    contextualcards \
    settings-logtags \
    zxing-core-1.7

include frameworks/base/packages/SettingsLib/common.mk
include frameworks/base/packages/SettingsLib/search/common.mk

include $(BUILD_PACKAGE)

#############################################################
# Settings Robolectric test target.                         #
#############################################################
include $(CLEAR_VARS)

LOCAL_MODULE := SettingsRoboTests
LOCAL_MODULE_CLASS := JAVA_LIBRARIES

LOCAL_SRC_FILES := $(call all-java-files-under, src) \
    $(call all-java-files-under, ../../../../../frameworks/base/packages/SettingsLib/tests/robotests/src/com/android/settingslib/testutils)
@@ -17,10 +75,13 @@ LOCAL_JAVA_LIBRARIES := \
    mockito-robolectric-prebuilt \
    truth-prebuilt

LOCAL_INSTRUMENTATION_FOR := Settings
LOCAL_INSTRUMENTATION_FOR := SettingsTest

LOCAL_MODULE_TAGS := optional

# Generate test_config.properties
include external/robolectric-shadows/gen_test_config.mk

include $(BUILD_STATIC_JAVA_LIBRARY)

#############################################################
@@ -37,7 +98,7 @@ LOCAL_JAVA_LIBRARIES := \
    mockito-robolectric-prebuilt \
    truth-prebuilt

LOCAL_TEST_PACKAGE := Settings
LOCAL_TEST_PACKAGE := SettingsTest

LOCAL_INSTRUMENT_SOURCE_DIRS := $(dir $(LOCAL_PATH))../src \
    frameworks/base/packages/SettingsLib/search/src \
+1 −4
Original line number Diff line number Diff line
manifest=packages/apps/Settings/AndroidManifest.xml
sdk=NEWEST_SDK

shadows=\
   com.android.settings.testutils.shadow.ShadowThreadUtils,\
   com.android.settingslib.testutils.shadow.ShadowXmlUtils
   com.android.settings.testutils.shadow.ShadowThreadUtils
+20 −0
Original line number Diff line number Diff line
<!--
  Copyright (C) 2018 The Android Open Source Project

  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.
  -->

<resources>
    <!-- List of packages that should be whitelisted for slice uri access. Do not translate -->
    <string-array name="slice_whitelist_package_names" translatable="false"/>
</resources>
+2 −2
Original line number Diff line number Diff line
@@ -4,20 +4,20 @@ import static com.google.common.truth.Truth.assertThat;

import android.content.Context;

import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.XmlTestUtils;
import com.android.settings.testutils.shadow.ShadowPowerManager;
import com.android.settingslib.core.AbstractPreferenceController;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;

import java.util.ArrayList;
import java.util.List;

@RunWith(SettingsRobolectricTestRunner.class)
@RunWith(RobolectricTestRunner.class)
public class DisplaySettingsTest {

    @Test
+2 −2
Original line number Diff line number Diff line
@@ -20,19 +20,19 @@ import static com.google.common.truth.Truth.assertThat;

import android.content.Intent;

import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowHelpUtils;

import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
import org.robolectric.shadows.ShadowActivity;

@RunWith(SettingsRobolectricTestRunner.class)
@RunWith(RobolectricTestRunner.class)
@Config(shadows = ShadowHelpUtils.class)
public class HelpTrampolineTest {

Loading