我正在为a编写测试ContentProvider,insert我正在通知更改getContext().getContentResolver().notifyChange(mUri, null);
我的测试类扩展ProviderTestCase2.我创建了以下模拟ContentObserver类:
private class ContentObserverMock extends ContentObserver {
public boolean changed = false;
public ContentObserverMock(Handler handler) {
super(handler);
// TODO Auto-generated constructor stub
}
@Override
public void onChange(boolean selfChange) {
changed = true;
}
@Override
public boolean deliverSelfNotifications() {
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
这是测试用例:
public void testInsertNotifyContentChanges() {
ContentResolver resolver = mContext.getContentResolver();
ContentObserverMock co = new ContentObserverMock(null);
resolver.registerContentObserver(CONTENT_URI, true, co);
ContentValues values = new ContentValues();
values.put(COLUMN_TAG_ID, 1);
values.put(COLUMN_TAG_CONTENT, "TEST");
resolver.insert(CONTENT_URI, values);
assertTrue(co.changed); …Run Code Online (Sandbox Code Playgroud) 我一直在努力解决这个问题,我认为我没有得到关于Robolectric的一些基本信息.通常一些谷歌搜索可以帮助我解决这类问题的底部,但在此之间,看看示例代码,我找不到任何有用的东西.
我试图模拟列表视图项的单击并检查单击后是否启动了一个活动.我一直回想起我正在测试的当前活动是由此产生的活动.我尝试删除所有列表项单击代码并检查生成的活动,然后将其作为我正在测试的InstallationListActivity返回.所以我得出的结论是列表视图项没有被点击,我只是不确定为什么.我在下面的测试代码中设置的系统日志是我期望的值.该列表是13项,getChildAt(0)返回标题.我认为获取第一个项目(getChildAt(1))并在其上调用performClick或其子文本视图将启动我的预期活动,但似乎并非如此.无论如何,这是我正在使用的robolectric /测试代码:
@Before
public void setUp() {
mAppLaunch = new ApplicationLaunchActivity();
mAppLaunch.onCreate(null);
mActivity = new InstallationListActivity();
mActivity.onCreate(null);
}
@Test
public void shouldHaveNonEmptyInstallationList() throws Exception {
assert(mActivity.installationListCount() > 0);
}
@Test
public void shouldHaveSameNumberOfElements() throws Exception {
ListView installationListView = (ListView) mActivity.getListView();
ShadowListView shadowListView = shadowOf(installationListView);
assert(shadowListView.getChildCount() == mActivity.installationListCount());
}
@Test
public void pressingTheFirstItemInTheListShouldLaunchVenueListActivity() {
ListView installationListView = (ListView) mActivity.findViewById(android.R.id.list);
System.out.println("qty: " + installationListView.getChildCount());
System.out.println("class: " + installationListView.getChildAt(0).getClass());
System.out.println("class: " + installationListView.getChildAt(1).getClass());
System.out.println("class: " + installationListView.getChildAt(2).getClass());
System.out.println("class: " + installationListView.getChildAt(3).getClass()); …Run Code Online (Sandbox Code Playgroud) testing android integration-testing robolectric android-testing
我正在尝试从特定视图访问按钮.相同的视图显示6次.这是我正在使用的代码.
public void testTimeConfig(){
onData(withDesc("description")).onChildView(withId(R.id.positive)).perform(click());
}
private static Matcher<Object> withDesc(String desc) {
return allOf(is(instanceOf(String.class)), is(desc));
}
Run Code Online (Sandbox Code Playgroud)
当我跑步时,我收到一个错误:
在视图上执行'加载适配器数据'时出错'可从类中分配:class android.widget.AdapterView'.
这是访问子视图的最佳方式吗?如果是这样,怎么样?
这是我现在尝试使用的代码.
Run Code Online (Sandbox Code Playgroud)onView(allOf((withContentDescription("description")), hasSibling(withContentDescription("SettingsLayout")), hasSibling(withId(R.id.positive)))).perform(click());
和
Run Code Online (Sandbox Code Playgroud)onView(allOf((withContentDescription("description")), hasSibling(withId(R.id.positive)))).perform(click());
出现此错误:
Run Code Online (Sandbox Code Playgroud)No views in hierarchy found matching
<view
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/setAGoalTitle"
android:layout_alignParentLeft="true"
class="com.xxx"
android:layout_marginTop="30dp"
android:id="@+id/timeGoalWidget"
app:goalLabel="@string/time_min_upper"
app:icon="@drawable/ic_icn_summary_time"
app:step="300"
app:valueFormat="time"
android:gravity="center_horizontal"
android:layout_marginBottom="60dp"
android:contentDescription="setAGoalTimeConfigurator"/>
<view
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="@id/timeGoalWidget"
class="com.xxx"
android:id="@+id/distanceGoalWidget"
app:goalLabel="@string/distance_upper"
app:icon="@drawable/ic_icn_summary_track"
app:step="0.25"
app:valueFormat="decimal_two"
android:gravity="center_horizontal"
android:contentDescription="setAGoalDistanceConfigurator"/>
<view
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/timeGoalWidget"
android:layout_alignLeft="@id/timeGoalWidget"
class="com.xxx"
android:id="@+id/paceGoalWidget"
app:goalLabel="@string/pace_upper"
app:icon="@drawable/ic_icn_summary_pace"
app:valueFormat="time"
app:step="10"
android:gravity="center_horizontal"
android:layout_marginBottom="60dp"
android:contentDescription="setAGoalPaceConfigurator"/>
<view
android:layout_width="wrap_content" …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Proguard打开测试Android应用的发布版本.我为测试依赖项创建了额外的Proguard规则文件,该文件包含在发布规则文件中.
-keep class android.test.** { *; }
-dontwarn android.test.**
# Reuse the release ProGuard mapping
-applymapping proguard.map
-dontshrink
-dontoptimize
Run Code Online (Sandbox Code Playgroud)
一切都编译好但在运行时失败.
java.lang.NoSuchMethodError: android.test.AndroidTestRunner.addTestListener
at com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.start(ProGuard:135)
at com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner$BridgeTestRunner.start(ProGuard:249)
at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:389)
at com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner.onCreate(ProGuard:114)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4702)
at android.app.ActivityThread.access$1600(ActivityThread.java:172)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1362)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5586)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)
我正在使用Espresso进行测试,仪表运行器的定义是 build.gradle
defaultConfig {
testApplicationId 'package.name.test'
testInstrumentationRunner 'com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner'
}
Run Code Online (Sandbox Code Playgroud)
有没有机会为proguarded发布版本运行测试?我从五月开始找到主题,看起来这是不可能的.对我来说,看起来它只是错误的Proguard配置(缺少方法),但该线-keep class android.test.** { *; }应该解决这个问题.我错过了什么吗?
android proguard android-testing android-gradle-plugin android-espresso
对于我的仪器测试我正在使用Robotium.大多数情况下,除了离线情况,我能够测试一切.
只要我禁用数据(使用adb,模拟器中的F8快捷键等等),测试就会断开连接.它继续在设备/模拟器中,但没有报告结果.
所以,我有一个想法,只将应用程序放在离线模式而不是整个设备.问题是我不知道怎么样......
使用iptablesApi我需要root我的设备.我已经读过,Mobiwol应用程序使用某种VPN来限制应用程序的互联网访问,而无需生根设备.
问题Mobiwol应用程序 如何阻止每个应用程序的互联网连接?或者还有其他方法可以离线测试apks吗?
编辑12/30/2014
我忘了说我可以脱机运行测试,但是当设备处于脱机状态时我必须开始测试.目前,我将测试分为OFFLINE和ONLINE.运行ONLINEs后,我执行着名的adb kill-server和adb start-server.之后我执行OFFLINEs.
我们有一个库项目,多个应用程序依赖于它.单元测试在库项目中.我们能够从Android Studio中的依赖项目运行测试,但是
./gradlew :[DependentProject]:connectedAndroidTest
Run Code Online (Sandbox Code Playgroud)
总是返回"没有找到测试,无事可做".
通过观察,我发现在Android Studio中,它似乎只执行gradle任务:
:[DependentProject]:assembleDebug, :[DependentProject]assembleDebugTest
Run Code Online (Sandbox Code Playgroud)
然后使用adb安装目标并测试apk,adb shell是运行测试的工具.
由于connectedAndroidTest依赖于这两个任务,我安装了它生成的目标和测试apks,并手动调用了instrument命令,测试开始了.
adb shell am instrument -w com.package.test/android.test.InstrumentationTestRunner
Run Code Online (Sandbox Code Playgroud)
然后问题来了,connectedAndroidTest在哪里寻找测试,以及为什么adb仪器可以找不到测试?如何解决这个问题?
android gradle android-testing android-studio android-gradle-plugin
我知道这对所有Android开发者来说都是一个乏味的话题.但究竟什么是Android测试的正确方法?
这是我可以想象的.
70%单元测试(JUnit测试所有业务逻辑,网络层,数据库层等......)
20%集成测试(也许针对模拟服务器进行测试?主要测试API结果?)
10%的UI测试(模拟除UI交互之外的任何其他内容,很可能是Mockito + Espresso)
这是其他人都在追随的还是另一种模式?
提前致谢!
我想做什么和问题
我将Android Studio和Android Gradle Plugin更新为3.0.0,将Gradle Wrapper更新为4.2.1,并希望通过IDE在设备上构建和部署我的Android Gradle项目.
当我尝试将我的:app模块部署到连接的设备时,我收到错误:
错误:配置项目':integration-test'时出现问题.变体'debug'没有类型'INSTANT_RUN_MERGED_MANIFESTS'的输出
项目详情(简化)
该项目包括:
settings.gradle
include :library
include :app
include :integration-test
Run Code Online (Sandbox Code Playgroud)
AndroidManifest.xml中
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.domain.integration_test">
<!-- from https://stackoverflow.com/questions/45631959/how-to-place-android-instrumentation-test-files-outside-of-project-directory -->
<!-- Specify runner and target application package -->
<instrumentation
android:name="android.support.test.runner.AndroidJUnitRunner"
android:functionalTest="false"
android:handleProfiling="false"
android:label="Tests for com.domain.pro.client"
android:targetPackage="com.domain.pro.client"/>
<application>
<uses-library android:name="android.test.runner" />
</application>
Run Code Online (Sandbox Code Playgroud)
上次它的工作原理是: - Build Tools 2.2.3,Gradle 3.4.1和Android Studio 2.3.3
题
有没有人使用com.android.test插件(使用AndroidManifest文件)与Android Gradle …
android android-testing gradle-android-test-plugi android-studio-3.0 android-gradle-3.0
在启用Android Test Orchestrator的情况下运行Espresso测试时,测试在没有调试器的情况下运行良好,但在使用Debugger开始测试时,测试只会挂起以下logcat消息:
I/AndroidTestOrchestrator: Waiting for debugger to connect...
如果我禁用Android Test Orchestrator,测试也可以运行Debugger.
任何想法如何使这个工作或这是一个已知的问题?
So I'm using the Android Management API to manage and handle deployment for an app to a kiosk device I am working on.
I've created an organisation, created a policy, and ensured the app is limited to managed google play only, and assigned the organisation to the app.
I've enrolled some devices onto the policy, and when the app is moved to prod (currently this is fine as there are only a handful of test devices on that policy), it …
android google-play android-testing android-enterprise android-management-api
android-testing ×10
android ×9
google-play ×1
gradle ×1
hamcrest ×1
proguard ×1
robolectric ×1
testing ×1
unit-testing ×1