使用CLI并使用以下命令运行模拟器:
./emulator -use-system-libs @Nexus5API25
Run Code Online (Sandbox Code Playgroud)
仅显示错误,并且模拟器无法启动.
emulator: ERROR: There's another emulator instance running with the current AVD 'Nexus5API25'. Exiting...
Run Code Online (Sandbox Code Playgroud)
和:
使用-verbose执行时会打印出更多详细信息但我没有看到任何可以帮助我解决问题的内容:
emulator:Android emulator version 26.1.3.0 (build_id 4205252) (CL:e55642d861e04276b2fa453bfaff4a836f3a3269)
emulator:Found AVD name 'Nexus5API25'
emulator:Found AVD target architecture: x86_64
emulator:argv[0]: './emulator'; program directory: '/home/developer/opt/Android/Sdk/emulator'
emulator: Found directory: /home/developer/opt/Android/Sdk/system-images/android-25/google_apis/x86_64/
emulator:Probing for /home/developer/opt/Android/Sdk/system-images/android-25/google_apis/x86_64//kernel-ranchu: file exists
emulator:Auto-config: -engine qemu2 (based on configuration)
emulator: Found directory: /home/developer/opt/Android/Sdk/system-images/android-25/google_apis/x86_64/
emulator:try dir /home/developer/opt/Android/Sdk/emulator
emulator:Found target-specific 64-bit emulator binary: /home/developer/opt/Android/Sdk/emulator/qemu/linux-x86_64/qemu-system-x86_64
emulator:Adding library search path: '/home/developer/opt/Android/Sdk/emulator/lib64'
emulator:Adding library …Run Code Online (Sandbox Code Playgroud) 我为我的应用程序编写了一个 espresso UI 测试,并且对于某些视图(在本例中为 ImageButton)perform(click())不起作用,也没有显示错误。这是行不通的:
try {
Thread.sleep(TIME_NORMAL_ELPASED);
} catch (InterruptedException e) {
e.printStackTrace();
}
onView(allOf(withId(R.id.toolbar_navigation_btn)
, isCompletelyDisplayed())).perform(click());
Run Code Online (Sandbox Code Playgroud)
这是我的 xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="activities.DepartFlight.fragments.AvailableFragment">
<android.support.v7.widget.Toolbar
android:id="@+id/available_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:layout_alignParentTop="true"
android:background="@drawable/background_toolbar">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageButton
android:id="@+id/toolbar_navigation_btn"
android:layout_width="@dimen/icon_toolbar"
android:layout_height="@dimen/icon_toolbar"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:background="@drawable/button_selector"
android:rotation="180"
android:src="@drawable/ic_back"
android:tint="@color/white" />
<com.faranegar.bookflight.customView.CustomTextView
android:id="@+id/text_toolbar_flight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="2dp"
android:textColor="@color/white" />
<com.faranegar.bookflight.customView.CustomTextView
android:id="@+id/toolbar_subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/text_toolbar_flight"
android:layout_centerHorizontal="true"
android:textColor="@color/white"
android:textSize="@dimen/font_size" />
</RelativeLayout>
</android.support.v7.widget.Toolbar>
<include
android:id="@+id/zero_filtered_items"
android:visibility="gone"
layout="@layout/zero_filterd_itesm_row" />
<com.faranegar.bookflight.customView.CustomRecyclerView
android:id="@+id/available_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/depart_flight_activity_footer"
android:layout_below="@id/available_toolbar" …Run Code Online (Sandbox Code Playgroud) 比方说,我在Flutter中使用了一个屏幕测试WidgetTester.有一个按钮,通过执行导航Navigator.我想测试该按钮的行为.
空间/屏幕
class MyScreen extends StatefulWidget {
MyScreen({Key key}) : super(key: key);
@override
_MyScreenState createState() => _MyScreenScreenState();
}
class _MyScreenState extends State<MyScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: RaisedButton(
onPressed: () {
Navigator.of(context).pushNamed("/nextscreen");
},
child: Text(Strings.traktTvUrl)
)
)
);
}
}
Run Code Online (Sandbox Code Playgroud)
测试
void main() {
testWidgets('Button is present and triggers navigation after tapped',
(WidgetTester tester) async {
await tester.pumpWidget(MaterialApp(home: MyScreen()));
expect(find.byType(RaisedButton), findsOneWidget);
await tester.tap(find.byType(RaisedButton));
//how to test navigator?
});
}
Run Code Online (Sandbox Code Playgroud)
我有一个正确的方法如何检查,导航器被调用?或者有没有办法模拟和替换导航器? …
我想检查一个视图是否没有被另一个视图隐藏。我没有成功地使用经典isDisplayed断言来测试这一点。
就我而言,我在同一布局(FrameLayout)内有一个视图 A 和一个视图 B。我想测试视图 A 对用户是否可见。但我知道,这个测试应该失败,因为视图 B 与视图 A 完全重叠。
布局示例:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<View android:id="@+id/view_a"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<View android:id="@+id/view_b"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</FrameLayout/>
Run Code Online (Sandbox Code Playgroud)
测试代码:
onView(
withId(R.id.view_a)
).check(
matches(
isDisplayed()
)
)
Run Code Online (Sandbox Code Playgroud)
正如我之前所说,即使视图 B 完全位于视图 A 上方,此测试也不会失败。
如何使用 espresso 来测试我的视图 A 实际上对用户可见?例如,当使用translateX/Y任何其他方式移动或隐藏视图 B 时。