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

Commit c4b6c23e authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add ravenwood minimum test" into main

parents 25353472 2d26539c
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -5,6 +5,10 @@
    }
  ],
  "ravenwood-presubmit": [
    {
      "name": "RavenwoodMinimumTest",
      "host": true
    },
    {
      "name": "RavenwoodMockitoTest",
      "host": true
+24 −0
Original line number Diff line number Diff line
package {
    // See: http://go/android-license-faq
    // A large-scale-change added 'default_applicable_licenses' to import
    // all of the 'license_kinds' from "frameworks_base_license"
    // to get the below license kinds:
    //   SPDX-license-identifier-Apache-2.0
    default_applicable_licenses: ["frameworks_base_license"],
}

// Minimum ravenwood test according to test-authors.md.
android_ravenwood_test {
    name: "RavenwoodMinimumTest",

    static_libs: [
        "androidx.annotation_annotation",
        "androidx.test.rules",
    ],

    srcs: [
        "test/**/*.java",
    ],
    sdk_version: "test_current",
    auto_gen_config: true,
}
+45 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.ravenwood;

import android.platform.test.annotations.IgnoreUnderRavenwood;
import android.platform.test.ravenwood.RavenwoodRule;

import androidx.test.runner.AndroidJUnit4;

import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class RavenwoodMinimumTest {
    @Rule
    public RavenwoodRule mRavenwood = new RavenwoodRule.Builder()
            .setProcessApp()
            .build();

    @Test
    public void testSimple() {
        Assert.assertTrue(android.os.Process.isApplicationUid(android.os.Process.myUid()));
    }

    @Test
    @IgnoreUnderRavenwood
    public void testIgnored() {
        throw new RuntimeException("Shouldn't be executed under ravenwood");
    }
}
+16 −0
Original line number Diff line number Diff line
@@ -31,6 +31,14 @@ android_ravenwood_test {
* Write your unit test just like you would for an Android device:

```
import android.platform.test.annotations.IgnoreUnderRavenwood;
import android.platform.test.ravenwood.RavenwoodRule;

import androidx.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class MyCodeTest {
    @Test
@@ -43,6 +51,14 @@ public class MyCodeTest {
* APIs available under Ravenwood are stateless by default.  If your test requires explicit states (such as defining the UID you’re running under, or requiring a main `Looper` thread), add a `RavenwoodRule` to declare that:

```
import android.platform.test.annotations.IgnoreUnderRavenwood;
import android.platform.test.ravenwood.RavenwoodRule;

import androidx.test.runner.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class MyCodeTest {
    @Rule