Update the .bp file and the skeleton of ArtServiceTests.
- Change the test to `android_test`, which is commonly used for mainline
module unit tests. (`java_test` doesn't work with Mockito, which is an
essential library for unit testing. It may also cause other problems
in the future.)
- Specify sdk_version and min_sdk_version.
- Migrate the test to using Mockito JUnit test runner.
- Migrate the test to using Truth.
Bug: 177273468
Test: atest ArtServiceTests
Ignore-AOSP-first: Will cherry-pick later.
Change-Id: I7c25b3cf95b6fd5ee7d749bf08cfdd8c41ba89c9
diff --git a/libartservice/tests/Android.bp b/libartservice/tests/Android.bp
index dc110a1..1b18cc5 100644
--- a/libartservice/tests/Android.bp
+++ b/libartservice/tests/Android.bp
@@ -27,7 +27,7 @@
default_applicable_licenses: ["art_license"],
}
-java_test {
+android_test {
name: "ArtServiceTests",
// Include all test java files.
@@ -36,9 +36,15 @@
],
static_libs: [
+ "androidx.test.ext.junit",
+ "androidx.test.ext.truth",
"androidx.test.runner",
+ "mockito-target-minus-junit4",
"service-art.impl",
],
+ sdk_version: "system_server_current",
+ min_sdk_version: "31",
+
test_suites: ["general-tests"],
}
diff --git a/libartservice/tests/AndroidManifest.xml b/libartservice/tests/AndroidManifest.xml
new file mode 100644
index 0000000..921bde9
--- /dev/null
+++ b/libartservice/tests/AndroidManifest.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+ ~ Copyright (C) 2022 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.
+ -->
+
+<manifest
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.server.art.tests">
+
+ <application android:label="ArtServiceTests">
+ <uses-library android:name="android.test.runner" />
+ </application>
+
+ <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
+ android:targetPackage="com.android.server.art.tests"
+ android:label="Tests for ART Serices" />
+</manifest>
diff --git a/libartservice/tests/src/com/android/server/art/ArtManagerLocalTests.java b/libartservice/tests/src/com/android/server/art/ArtManagerLocalTests.java
index 515849b..b0323c4 100644
--- a/libartservice/tests/src/com/android/server/art/ArtManagerLocalTests.java
+++ b/libartservice/tests/src/com/android/server/art/ArtManagerLocalTests.java
@@ -16,22 +16,29 @@
package com.android.server.art;
-import static org.junit.Assert.assertTrue;
+import static com.google.common.truth.Truth.assertThat;
-import androidx.test.runner.AndroidJUnit4;
+import androidx.test.filters.SmallTest;
import com.android.server.art.ArtManagerLocal;
-import junit.framework.TestCase;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
-public class ArtManagerLocalTests extends TestCase {
+@SmallTest
+@RunWith(MockitoJUnitRunner.class)
+public class ArtManagerLocalTests {
private ArtManagerLocal mArtManagerLocal;
- public void setup() {
+ @Before
+ public void setUp() {
mArtManagerLocal = new ArtManagerLocal();
}
+ @Test
public void testScaffolding() {
- assertTrue(true);
+ assertThat(true).isTrue();
}
-}
\ No newline at end of file
+}