diff options
author | Joe LaPenna <jlapenna@google.com> | 2017-02-03 12:47:21 -0800 |
---|---|---|
committer | Joe LaPenna <jlapenna@google.com> | 2017-02-03 13:20:17 -0800 |
commit | a6d5d1bf8d382adb726d1b8f139cb44eec3e6081 (patch) | |
tree | b3e3fb51debbf283f808b6f07577105cfec5fd1e | |
parent | 3ae41f6a9cd5e508baf751d0f8a8507a88cf16aa (diff) | |
download | NetworkRecommendation-a6d5d1bf8d382adb726d1b8f139cb44eec3e6081.tar.gz |
Add robolectric support for netrec.
Bug: 34944625
Test: mm -j64 RunNetworkRecommendationRoboTests
Change-Id: I1dd78e37db973c82e7742b35a3100b4424beb8fa
-rw-r--r-- | PREUPLOAD.cfg | 1 | ||||
-rw-r--r-- | robotests/Android.mk | 43 | ||||
-rw-r--r-- | robotests/src/com/android/networkrecommendation/ExampleTest.java | 57 |
3 files changed, 101 insertions, 0 deletions
diff --git a/PREUPLOAD.cfg b/PREUPLOAD.cfg index 2673295..f407d06 100644 --- a/PREUPLOAD.cfg +++ b/PREUPLOAD.cfg @@ -1,5 +1,6 @@ [Hook Scripts] checkstyle_hook = ${REPO_ROOT}/prebuilts/checkstyle/checkstyle.py --sha ${PREUPLOAD_COMMIT} +robotest_hook = make -C ../../.. -j32 RunNetworkRecommendationRoboTests [Builtin Hooks] commit_msg_bug_field = true diff --git a/robotests/Android.mk b/robotests/Android.mk new file mode 100644 index 0000000..3ed28c0 --- /dev/null +++ b/robotests/Android.mk @@ -0,0 +1,43 @@ +############################################# +# Add app-specific 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 + +# TODO: Remove the use of LOCAL_INSTRUMENTATION_FOR and use a different build flag. +LOCAL_INSTRUMENTATION_FOR := NetworkRecommendation +LOCAL_MODULE := NetworkRecommendationRoboTests + +LOCAL_MODULE_TAGS := optional + +include $(BUILD_STATIC_JAVA_LIBRARY) + +############################################################# +# Add Robolectric runner target to run the previous target. # +############################################################# +include $(CLEAR_VARS) + +LOCAL_MODULE := RunNetworkRecommendationRoboTests + +LOCAL_SDK_VERSION := current + +LOCAL_STATIC_JAVA_LIBRARIES := \ + NetworkRecommendationRoboTests + +LOCAL_TEST_PACKAGE := NetworkRecommendation + +LOCAL_ROBOTEST_FAILURE_FATAL := true + +include prebuilts/misc/common/robolectric/run_robotests.mk diff --git a/robotests/src/com/android/networkrecommendation/ExampleTest.java b/robotests/src/com/android/networkrecommendation/ExampleTest.java new file mode 100644 index 0000000..c81633a --- /dev/null +++ b/robotests/src/com/android/networkrecommendation/ExampleTest.java @@ -0,0 +1,57 @@ +/* + * 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.networkrecommendation; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertTrue; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + +import android.app.job.JobInfo; +import android.app.job.JobScheduler; +import android.content.Context; +import android.content.Intent; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.ArgumentCaptor; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.annotation.Config; +import java.util.List; + +@RunWith(RobolectricTestRunner.class) +@Config(manifest="packages/services/NetworkRecommendation/AndroidManifest.xml", sdk=23) +public class ExampleTest { + @Mock private Context mMockContext; + @Mock private JobScheduler mJobScheduler; + @Mock private Intent mMockIntent; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void example() { + // pass + } +} |