Add robolectric test
Configure the build target and migrate LinkSpanTest to Robolectric. Move existing instrumentation tests into test/instrumentation Bug: 32975598 Test: ./gradlew test Change-Id: I9bb39142c616a2c44fe38f48d92e89ab8ebda7ba
This commit is contained in:
parent
4819fa7e3e
commit
2e634640f3
|
@ -9,9 +9,9 @@ apply from: 'standalone-rules.gradle'
|
||||||
// Add targets for tests
|
// Add targets for tests
|
||||||
android.sourceSets {
|
android.sourceSets {
|
||||||
androidTest {
|
androidTest {
|
||||||
manifest.srcFile 'test/AndroidManifest.xml'
|
manifest.srcFile 'test/instrumentation/AndroidManifest.xml'
|
||||||
java.srcDirs = ['test/src']
|
java.srcDirs = ['test/instrumentation/src']
|
||||||
res.srcDirs = ['test/res']
|
res.srcDirs = ['test/instrumentation/res']
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
androidTestCompile 'com.android.support.test:rules:0.5'
|
androidTestCompile 'com.android.support.test:rules:0.5'
|
||||||
|
@ -36,6 +36,17 @@ android.sourceSets {
|
||||||
java.srcDirs = ['full-support/test/src', 'eclair-mr1/test/src']
|
java.srcDirs = ['full-support/test/src', 'eclair-mr1/test/src']
|
||||||
res.srcDirs = ['full-support/test/res']
|
res.srcDirs = ['full-support/test/res']
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test {
|
||||||
|
java.srcDirs = ['test/robotest/src']
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
testCompile 'org.robolectric:robolectric:3.+'
|
||||||
|
testCompile 'org.robolectric:shadows-core:3.+'
|
||||||
|
testCompile 'junit:junit:4.+'
|
||||||
|
testCompile 'org.mockito:mockito-core:1.9.5'
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
android.defaultConfig.testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
android.defaultConfig.testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
|
|
||||||
|
|
|
@ -46,23 +46,23 @@ public class BottomScrollViewTest {
|
||||||
@Test
|
@Test
|
||||||
public void testNoNeedScroll() {
|
public void testNoNeedScroll() {
|
||||||
createScrollView(20);
|
createScrollView(20);
|
||||||
assertTrue("Scroll should not be required", mListener.scrolledToBottom);
|
assertTrue("Scroll should not be required", mListener.mScrolledToBottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNeedScroll() {
|
public void testNeedScroll() {
|
||||||
createScrollView(110);
|
createScrollView(110);
|
||||||
assertFalse("Scroll should be required", mListener.scrolledToBottom);
|
assertFalse("Scroll should be required", mListener.mScrolledToBottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testScrollToBottom() {
|
public void testScrollToBottom() {
|
||||||
final BottomScrollView bottomScrollView = createScrollView(110);
|
final BottomScrollView bottomScrollView = createScrollView(110);
|
||||||
|
|
||||||
assertFalse("Scroll should be required", mListener.scrolledToBottom);
|
assertFalse("Scroll should be required", mListener.mScrolledToBottom);
|
||||||
|
|
||||||
bottomScrollView.scrollTo(0, 10);
|
bottomScrollView.scrollTo(0, 10);
|
||||||
assertTrue("Should already be scrolled to bottom", mListener.scrolledToBottom);
|
assertTrue("Should already be scrolled to bottom", mListener.mScrolledToBottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -90,7 +90,7 @@ public class BottomScrollViewTest {
|
||||||
private static final int WIDTH = 10;
|
private static final int WIDTH = 10;
|
||||||
private int mHeight;
|
private int mHeight;
|
||||||
|
|
||||||
public TestChildView(Context context, int height) {
|
TestChildView(Context context, int height) {
|
||||||
super(context);
|
super(context);
|
||||||
mHeight = height;
|
mHeight = height;
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ public class BottomScrollViewTest {
|
||||||
|
|
||||||
private static class TestBottomScrollView extends BottomScrollView {
|
private static class TestBottomScrollView extends BottomScrollView {
|
||||||
|
|
||||||
public TestBottomScrollView(Context context) {
|
TestBottomScrollView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,16 +121,16 @@ public class BottomScrollViewTest {
|
||||||
|
|
||||||
private static class TestBottomScrollListener implements BottomScrollView.BottomScrollListener {
|
private static class TestBottomScrollListener implements BottomScrollView.BottomScrollListener {
|
||||||
|
|
||||||
boolean scrolledToBottom = true;
|
boolean mScrolledToBottom = true;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onScrolledToBottom() {
|
public void onScrolledToBottom() {
|
||||||
scrolledToBottom = true;
|
mScrolledToBottom = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRequiresScroll() {
|
public void onRequiresScroll() {
|
||||||
scrolledToBottom = false;
|
mScrolledToBottom = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -131,7 +131,7 @@ public class DrawableLayoutDirectionHelperTest {
|
||||||
|
|
||||||
private static class ForceRtlView extends View {
|
private static class ForceRtlView extends View {
|
||||||
|
|
||||||
public ForceRtlView(Context context) {
|
ForceRtlView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,7 +104,7 @@ public class ListViewRequireScrollHelperTest {
|
||||||
public int scrollDistance = 0;
|
public int scrollDistance = 0;
|
||||||
public OnScrollListener listener;
|
public OnScrollListener listener;
|
||||||
|
|
||||||
public TestListView(Context context) {
|
TestListView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
setAdapter(new BaseAdapter() {
|
setAdapter(new BaseAdapter() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -149,7 +149,7 @@ public class ListViewRequireScrollHelperTest {
|
||||||
|
|
||||||
private static class TestNavigationBar extends NavigationBar {
|
private static class TestNavigationBar extends NavigationBar {
|
||||||
|
|
||||||
public TestNavigationBar(Context context) {
|
TestNavigationBar(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,7 +181,7 @@ public class PartnerTest {
|
||||||
private Context mTestContext;
|
private Context mTestContext;
|
||||||
private Resources mTestResources;
|
private Resources mTestResources;
|
||||||
|
|
||||||
public TestPackageManager(Context testContext) {
|
TestPackageManager(Context testContext) {
|
||||||
mTestContext = testContext;
|
mTestContext = testContext;
|
||||||
mTestResources = new TestResources();
|
mTestResources = new TestResources();
|
||||||
}
|
}
|
||||||
|
@ -209,7 +209,7 @@ public class PartnerTest {
|
||||||
|
|
||||||
public List<ResolveInfo> partnerList;
|
public List<ResolveInfo> partnerList;
|
||||||
|
|
||||||
public TestContext(Context context) {
|
TestContext(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@ public class RequireScrollHelperTest {
|
||||||
public BottomScrollListener listener;
|
public BottomScrollListener listener;
|
||||||
public int page = 0;
|
public int page = 0;
|
||||||
|
|
||||||
public TestBottomScrollView(Context context) {
|
TestBottomScrollView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ public class RequireScrollHelperTest {
|
||||||
|
|
||||||
private static class TestNavigationBar extends NavigationBar {
|
private static class TestNavigationBar extends NavigationBar {
|
||||||
|
|
||||||
public TestNavigationBar(Context context) {
|
TestNavigationBar(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
}
|
}
|
||||||
|
|
|
@ -237,7 +237,7 @@ public class SystemBarHelperTest {
|
||||||
private int mNavigationBarColor = -1;
|
private int mNavigationBarColor = -1;
|
||||||
private int mStatusBarColor = -1;
|
private int mStatusBarColor = -1;
|
||||||
|
|
||||||
public TestWindow(Context context, View decorView) {
|
TestWindow(Context context, View decorView) {
|
||||||
super(context);
|
super(context);
|
||||||
mDecorView = decorView;
|
mDecorView = decorView;
|
||||||
}
|
}
|
|
@ -1,3 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2016 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.setupwizardlib.test.util;
|
package com.android.setupwizardlib.test.util;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
|
@ -14,29 +14,25 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package com.android.setupwizardlib.test;
|
package com.android.setupwizardlib.span;
|
||||||
|
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
|
import static org.robolectric.RuntimeEnvironment.application;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.ContextWrapper;
|
import android.content.ContextWrapper;
|
||||||
import android.support.test.InstrumentationRegistry;
|
|
||||||
import android.support.test.filters.SmallTest;
|
|
||||||
import android.support.test.runner.AndroidJUnit4;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.android.setupwizardlib.span.LinkSpan;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
@SmallTest
|
|
||||||
public class LinkSpanTest {
|
public class LinkSpanTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOnClick() {
|
public void testOnClick() {
|
||||||
final TestContext context = new TestContext(InstrumentationRegistry.getContext());
|
final TestContext context = new TestContext(application);
|
||||||
final TextView textView = new TextView(context);
|
final TextView textView = new TextView(context);
|
||||||
final LinkSpan linkSpan = new LinkSpan("test_id");
|
final LinkSpan linkSpan = new LinkSpan("test_id");
|
||||||
|
|
||||||
|
@ -47,8 +43,7 @@ public class LinkSpanTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNonImplementingContext() {
|
public void testNonImplementingContext() {
|
||||||
final Context context = InstrumentationRegistry.getContext();
|
final TextView textView = new TextView(application);
|
||||||
final TextView textView = new TextView(context);
|
|
||||||
final LinkSpan linkSpan = new LinkSpan("test_id");
|
final LinkSpan linkSpan = new LinkSpan("test_id");
|
||||||
|
|
||||||
linkSpan.onClick(textView);
|
linkSpan.onClick(textView);
|
||||||
|
@ -61,7 +56,7 @@ public class LinkSpanTest {
|
||||||
|
|
||||||
public LinkSpan clickedSpan = null;
|
public LinkSpan clickedSpan = null;
|
||||||
|
|
||||||
public TestContext(Context base) {
|
TestContext(Context base) {
|
||||||
super(base);
|
super(base);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue