1 /* 2 * Copyright 2014 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 * Copyright (C) 2014 The Android Open Source Project 18 * 19 * Licensed under the Apache License, Version 2.0 (the "License"); 20 * you may not use this file except in compliance with the License. 21 * You may obtain a copy of the License at 22 * 23 * http://www.apache.org/licenses/LICENSE-2.0 24 * 25 * Unless required by applicable law or agreed to in writing, software 26 * distributed under the License is distributed on an "AS IS" BASIS, 27 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 28 * See the License for the specific language governing permissions and 29 * limitations under the License. 30 */ 31 package com.example.android.appusagestatistics; 32 33 import android.test.ActivityInstrumentationTestCase2; 34 35 /** 36 * Tests for {@link AppUsageStatisticsActivity}. 37 */ 38 public class AppUsageStatisticsActivityTests 39 extends ActivityInstrumentationTestCase2<AppUsageStatisticsActivity> { 40 41 private AppUsageStatisticsActivity mTestActivity; 42 private AppUsageStatisticsFragment mTestFragment; 43 44 public AppUsageStatisticsActivityTests() { 45 super(AppUsageStatisticsActivity.class); 46 } 47 48 @Override 49 protected void setUp() throws Exception { 50 super.setUp(); 51 52 // Starts the activity under test using the default Intent with: 53 // action = {@link Intent#ACTION_MAIN} 54 // flags = {@link Intent#FLAG_ACTIVITY_NEW_TASK} 55 // All other fields are null or empty. 56 mTestActivity = getActivity(); 57 mTestFragment = (AppUsageStatisticsFragment) 58 mTestActivity.getSupportFragmentManager().getFragments().get(0); 59 } 60 61 /** 62 * Test if the test fixture has been set up correctly. 63 */ 64 public void testPreconditions() { 65 //Try to add a message to add context to your assertions. These messages will be shown if 66 //a tests fails and make it easy to understand why a test failed 67 assertNotNull("mTestActivity is null", mTestActivity); 68 assertNotNull("mTestFragment is null", mTestFragment); 69 } 70 } 71