我尝试在espresso中为我的android应用程序编写一些测试,我遇到了Idle的问题.如果我的isIdleNow()看起来像这样
public boolean isIdleNow() {
return true;
}
Run Code Online (Sandbox Code Playgroud)
邮件已发送.但是如果IsIdleNow()必须等待某些条件(它在启动时不返回true),则不发送消息.我的代码
public class ImageViewIdlingResource implements IdlingResource {
private ImageView imageView=null;
ResourceCallback callback;
public ImageViewIdlingResource(ImageView imageView2){
this.imageView = imageView2;
}
@Override
public String getName() {
return "ImageViewIdlingResource";
}
@Override
public boolean isIdleNow() {
return !imageView.isShown();
}
@Override
public void registerIdleTransitionCallback(ResourceCallback resourceCallback) {
this.callback = resourceCallback;
}}
Run Code Online (Sandbox Code Playgroud)
并测试
public class EspressoTest extends ActivityInstrumentationTestCase2<SplashScreen> {
public EspressoTest() {
super(SplashScreen.class);
}
@Override
public void setUp() throws Exception {
super.setUp();
getActivity();
ImageViewIdlingResource imageResource = new ImageViewIdlingResource((ImageView)getActivity().findViewById(R.id.splashscreen_icon));
Espresso.registerIdlingResources(imageResource); …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写简单的 REST API。我使用 Database.SQLite.Simple、Scotty 和 Aeson。我在 ScottyM() 路由函数中遇到数据库查询问题。当我有这样的事情时
\n\nroutes :: [User] -> ScottyM ()\nroutes allUsers = do\n get "/users/:id" $ do\n id <- param "id"\n json ([x | x <- allUsers, userId x == id] !! 0)\n\nmain = do\n conn <- open "data.db"\n users <- ( query_ conn "select id, first_name, second_name, team from users" :: IO [User] )\n scotty 3000 (routes users)\nRun Code Online (Sandbox Code Playgroud)\n\n一切正常,但在这种情况下,allUsers 仅在服务器启动时更新一次。每次有人问起这个问题我都想问一下。所以我写了这个:
\n\nroutes :: Connection -> ScottyM ()\nroutes conn= do\n get "/users/:id" $ do\n …Run Code Online (Sandbox Code Playgroud)