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

Commit 975fc0b7 authored by android-build-team Robot's avatar android-build-team Robot
Browse files

release-request-48587b2e-b0d9-4e33-ae5f-05bd16bc9d6f-for-git_pi-release-430880...

release-request-48587b2e-b0d9-4e33-ae5f-05bd16bc9d6f-for-git_pi-release-4308806 snap-temp-L91400000098269614

Change-Id: I5039617e01a6787be1494c1d86031d2f2276fa6f
parents 282eaac3 7d9f2765
Loading
Loading
Loading
Loading

tests/Android.mk

0 → 100644
+5 −0
Original line number Diff line number Diff line
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

# Include all makefiles in subdirectories
include $(call all-makefiles-under,$(LOCAL_PATH))
+40 −0
Original line number Diff line number Diff line
#############################################
# Turbo Robolectric test target. #
#############################################
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

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

# Include the testing libraries (JUnit4 + Robolectric libs).
LOCAL_STATIC_JAVA_LIBRARIES := \
    platform-system-robolectric \
    truth-prebuilt

LOCAL_JAVA_LIBRARIES := \
    junit \
    platform-robolectric-prebuilt \
    sdk_vcurrent

LOCAL_INSTRUMENTATION_FOR := SettingsIntelligence
LOCAL_MODULE := SettingsIntelligenceRoboTests

LOCAL_MODULE_TAGS := optional

include $(BUILD_STATIC_JAVA_LIBRARY)

#############################################################
# Turbo runner target to run the previous target. #
#############################################################
include $(CLEAR_VARS)

LOCAL_MODULE := RunSettingsIntelligenceRoboTests

LOCAL_SDK_VERSION := system_current

LOCAL_STATIC_JAVA_LIBRARIES := \
    SettingsIntelligenceRoboTests

LOCAL_TEST_PACKAGE := SettingsIntelligence

include prebuilts/misc/common/robolectric/run_robotests.mk
+31 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.
 */

package com.android.settings.intelligence;

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

@RunWith(SettingsIntelligenceRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class DummyTest {

    @Test
    public void testRun() {
        
    }
}
+83 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.
 */

package com.android.settings.intelligence;

import java.util.List;
import org.junit.runners.model.InitializationError;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.manifest.AndroidManifest;
import org.robolectric.res.Fs;
import org.robolectric.res.ResourcePath;

/**
 * Custom test runner for dealing with resources from multiple sources. This is needed because the
 * default behavior for robolectric is just to grab the resource directory in the target package. We
 * want to override this to add several spanning different projects/libraries.
 */
public class SettingsIntelligenceRobolectricTestRunner extends RobolectricTestRunner {

    /** We don't actually want to change this behavior, so we just call super. */
    public SettingsIntelligenceRobolectricTestRunner(Class<?> testClass) throws InitializationError {
        super(testClass);
    }

    /**
     * We are going to create our own custom manifest so that we can add multiple resource paths to
     * it. This lets us access resources in different projects in our tests as well as use a test
     * res directory.
     */
    @Override
    protected AndroidManifest getAppManifest(Config config) {
        // Using the manifest file's relative path, we can figure out the application directory.
        final String appRoot = "vendor/unbundled_google/packages/Turbo";
        final String manifestPath = appRoot + "/AndroidManifest.xml";
        final String resDir = appRoot + "tests/robotests/res";
        final String assetsDir = appRoot + config.assetDir();

        // By adding any resources from libraries we need to the AndroidManifest, we can access
        // them from within the parallel universe's resource loader.
        final AndroidManifest manifest =
                new AndroidManifest(
                        Fs.fileFromPath(manifestPath),
                        Fs.fileFromPath(resDir),
                        Fs.fileFromPath(assetsDir)) {
                    @Override
                    public List<ResourcePath> getIncludedResourcePaths() {
                        List<ResourcePath> paths = super.getIncludedResourcePaths();
                        paths.add(
                                new ResourcePath(
                                        getPackageName(),
                                        Fs.fileFromPath(
                                                "./vendor/unbundled_google/packages/"
                                                        + "Turbo/tests/robotests/res"),
                                        null));
                        paths.add(
                                new ResourcePath(
                                        getPackageName(),
                                        Fs.fileFromPath(
                                                "./vendor/unbundled_google/packages/Turbo/res"),
                                        null));
                        return paths;
                    }
                };

        // Set the package name to the renamed one
        manifest.setPackageName("com.google.android.apps.turbo");
        return manifest;
    }
}
+26 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2017 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.
 */

package com.android.settings.intelligence;

/**
 * Constants for Robolectric config.
 */
public class TestConfig {
    public static final int SDK_VERSION = 23;
    public static final String MANIFEST_PATH =
            "packages/apps/SettingsIntelligence/Turbo/AndroidManifest.xml";
}