小编Bol*_*oso的帖子

Espresso - 使用异步加载的数据断言TextView

我正在使用谷歌Espresso for Android编写UI测试,我一直坚持如何断言TextView文本,这些内容是从Web服务异步加载的.我目前的代码是:

public class MyTest extends BaseTestCase<MyActivity>{
    public void setUp() throws Exception {
        // (1) Tell the activity to load 'element-to-be-loaded' from webservice
        this.setActivityIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("data://data/element-to-be-loaded")));
        getActivity();

        super.setUp();
    }

    public void testClickOnReviews(){
        // (2) Check the element is loaded and its name is displayed
        Espresso
            .onView(ViewMatchers.withId(R.id.element_name))
            .check(ViewAssertions.matches(ViewMatchers.withText("My Name")));

        // (3) Click on the details box
        Espresso
            .onView(ViewMatchers.withId(R.id.details_box))
            .check(ViewAssertions.matches(ViewMatchers.isDisplayed()))
            .perform(ViewActions.click());

        // (4) Wait for the details screen to open
        Espresso
            .onView(ViewMatchers.withId(R.id.review_box));

        // Go back to element screen
        Espresso.pressBack();
    }
} …
Run Code Online (Sandbox Code Playgroud)

android android-testing android-espresso

14
推荐指数
1
解决办法
2万
查看次数

持有应用程序Context实例是不好的做法?

根据我的理解,Android中的应用程序是一个单例(如果我错了,请纠正我),我们总是只有一个应用程序上下文实例.

那么,从这个角度来看,在我的Application类中保存应用程序Context是不好的做法吗?它会导致大量内存泄漏吗?

这是一个例子:

public class MyApp extends Application {
    private static Context appContext = null; // <-- here is the thing!

    @Override
    public void onCreate() {
        appContext = this;
    }

    public static Context getApplicationContextSingleton () {
        return MyApp.appContext;
    }
}
Run Code Online (Sandbox Code Playgroud)

这样做的原因是全局访问的类,如PreferencesManager,大多数静态方法总是需要上下文.因此,我不是每次都传递它(甚至将它存储在一个可能很糟糕的实例中),而是考虑存储应用程序上下文.有什么缺点我没看到?

android design-patterns android-context

10
推荐指数
1
解决办法
3287
查看次数

Google Espresso java.lang.RuntimeException:无法启动意图Intent {act = android.intent.action.MAIN

我是Espresso UI测试的新手.

我在运行测试时遇到此错误(ADT Eclipse IDE).

该应用程序已经开发,启动应用程序时会有很多请求.无法重写应用程序.但我需要找到测试此UI的方法,即使组件的加载有任何延迟.

        java.lang.RuntimeException: Could not launch intent Intent { act=android.intent.action.MAIN flg=0x14000000 cmp=com.xx.android/com.yy.core.android.map.MapActivity } within 45 seconds. Perhaps the main thread has not gone idle within a reasonable amount of time? There could be an animation or something constantly repainting the screen. Or the activity is doing network calls on creation? See the threaddump logs. For your reference the last time the event queue was idle before your activity launch request was 1390913271702 and and now the …
Run Code Online (Sandbox Code Playgroud)

eclipse android runtimeexception android-espresso

9
推荐指数
3
解决办法
1万
查看次数

PL/SQL传递函数作为参数

我在半年内用PL/SQL编程,我觉得它是一种非常简单的编程语言(恕我直言).虽然我偶然发现了一些有趣的文章,比如这篇文章 - PL/SQL中的设计模式 - 界面注入更加宽松的耦合,我建议阅读.谈到依赖注入,我想念一个特殊功能:将子程序作为参数传递.可能吗?怎么样?

例如,假设我在javascript中有这样的代码:

function tell_me (printer) {
  printer ("hello");
}

tell_me (function () {
  console.log (word);
});
Run Code Online (Sandbox Code Playgroud)

是否有可能在PL/SQL中做类似的事情?

parameters plsql functional-programming function

4
推荐指数
1
解决办法
3359
查看次数