我正在努力将项目推向espresso测试.我已阅读了大量文档,并按照给定的做法开始.
一切正常,但是,当谈到Intents相关测试时,结果很奇怪.
大多数情况下,测试在我的Mac中传递但在我的同事的Windows(并非所有测试都失败)中失败并显示失败消息java.lang.IllegalStateException: init() must be called prior to using this method.
非常奇怪的是,如果我们在Android Studio中运行Debug测试,则逐步执行代码,它会通过.
这是测试代码:
@RunWith(AndroidJUnit4.class)
@LargeTest
public class MainActivityTest {
@Rule public IntentsTestRule<MainActivity> mRule = new IntentsTestRule<>(MainActivity.class, true, false);
AccountManager accountManager;
MainActivity activity;
private void buildLoginStatus() throws AuthenticatorException {
DanteApp app = (DanteApp) InstrumentationRegistry.getTargetContext().getApplicationContext();
accountManager = app.getDanteAppComponent().accountManager();
DoctorModel doctorModel = AccountMocker.mockDoctorModel();
accountManager.save(doctorModel.doctor);
accountManager.setAccessToken(doctorModel.access_token, false);
}
@Before public void before() throws Exception {
buildLoginStatus();
// must login
assertThat(accountManager.hasAuthenticated(), is(true));
activity = mRule.launchActivity(null);
// block all of the …Run Code Online (Sandbox Code Playgroud) 我正在使用Picasso来帮助缓存图像.
问题是,如何访问下载的图像以进行共享意图?
有任何想法吗?谢谢!
我为列表视图编写了定制的项目布局。布局中有许多小部件,有些将具有自己的clicklistener。
当我单击该行时,有时listview的onListItemClick起作用,但有时不起作用。
经过一段时间的搜索后,我找到了一种方法,可以在布局的根目录中设置android:descendantFocusability =“ blocksDescendants”。它可以工作,但是只有一个textview无法工作(已尝试了可单击的,可折叠的属性)。在列表的适配器中,我设置了textview的onClickListener,它可以工作。但这不是自然,有人知道如何解决吗?
顺便说一句,有没有办法区分不同的小部件的点击?现在,无论我单击什么(除textview之外),整行的背景选择器都已更改。
非常感谢!
//我的列表行布局根
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:descendantFocusability="blocksDescendants"
android:padding="@dimen/medium"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
Run Code Online (Sandbox Code Playgroud)
//糟糕的textview
<TextView
android:id="@+id/text"
android:textColor="@android:color/secondary_text_light"
android:textColorLink="@android:color/holo_blue_dark"
android:layout_marginTop="@dimen/small"
android:textAppearance="@android:style/TextAppearance.DeviceDefault"
android:layout_below="@id/nick"
android:layout_alignLeft="@id/nick"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
Run Code Online (Sandbox Code Playgroud)
更新
textview使用Linkify提供一些链接功能。