• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.example.android.apis.app;
18 
19 import android.content.Intent;
20 import android.os.IBinder;
21 import android.test.ServiceTestCase;
22 
23 import androidx.test.filters.MediumTest;
24 import androidx.test.filters.SmallTest;
25 
26 /**
27  * This is a simple framework for a test of a Service.  See {@link android.test.ServiceTestCase
28  * ServiceTestCase} for more information on how to write and extend service tests.
29  *
30  * To run this test, you can type:
31  * adb shell am instrument -w \
32  *   -e class com.example.android.apis.app.LocalServiceTest \
33  *   com.example.android.apis.tests/android.test.InstrumentationTestRunner
34  */
35 public class LocalServiceTest extends ServiceTestCase<LocalService> {
36 
LocalServiceTest()37     public LocalServiceTest() {
38       super(LocalService.class);
39     }
40 
41     @Override
setUp()42     protected void setUp() throws Exception {
43         super.setUp();
44     }
45 
46     /**
47      * The name 'test preconditions' is a convention to signal that if this
48      * test doesn't pass, the test case was not set up properly and it might
49      * explain any and all failures in other tests.  This is not guaranteed
50      * to run before other tests, as junit uses reflection to find the tests.
51      */
52     @SmallTest
testPreconditions()53     public void testPreconditions() {
54     }
55 
56     /**
57      * Test basic startup/shutdown of Service
58      */
59     @SmallTest
testStartable()60     public void testStartable() {
61         Intent startIntent = new Intent();
62         startIntent.setClass(getContext(), LocalService.class);
63         startService(startIntent);
64     }
65 
66     /**
67      * Test binding to service
68      */
69     @MediumTest
testBindable()70     public void testBindable() {
71         Intent startIntent = new Intent();
72         startIntent.setClass(getContext(), LocalService.class);
73         IBinder service = bindService(startIntent);
74     }
75 
76 }
77