2
方法進行測試(在主要活動中)Android的測試:檢查LeftDrawable圖像是正確的
//This Method allows you to set the LeftDrawable Image to a grayed out (drawableDown)
//image for 300 millseconds then returns the LeftDrawable Image back to the orignal
//(drawableUp).On a button.
void buttonPressFeedbackLeft(final Button button, final int drawableDown,
final int drawableUp) {
button.setCompoundDrawablesWithIntrinsicBounds(drawableDown, 0, 0, 0);
button.postDelayed(new Runnable() {
public void run() {
button.setCompoundDrawablesWithIntrinsicBounds(drawableUp, 0,
0, 0);
}
}, 300);
}
測試在測試項目:(活動和我(意向)已設置)
public void testbuttonPressFeedback(){
/*
* Start activity
*/
activity = startActivity(i, null, null);
/*
* get the backButton
*/
Button backButton = (Button) activity.findViewById(R.id.bottem_bar_prev);
/*
* get the backButton image (up and down image) as a Drawable
*/
int drawableDown = R.drawable.ic_menu_back_gray;
int drawableUp = R.drawable.ic_menu_back;
/*
* create a Drawable with the ResId
*/
Drawable drawableDownImage = activity.getResources().getDrawable(drawableDown);
Drawable drawableUpImage = activity.getResources().getDrawable(drawableDown);
/*
* Simulate button being pressed (running the buttonPressFeedback() method)
*/
activity.buttonPressFeedbackLeft(prevButton, drawableDown, drawableUp);
/*
* get the drawable array [left, top, right, bottom]
* compare drawable with the drawable found on the button.
*/
Drawable[] d = prevButton.getCompoundDrawables();
assertEquals(drawableDownImage,d[0]);
}
堆棧跟蹤:
junit.framework.AssertionFailedError: expected:[email protected] but was:[email protected]
問題
我假設對象不一樣。所以我試圖調查獲取資源ID並比較它們,但我認爲這不可能?
是否有另一種方法來比較顯示在按鈕上的Drawable?
我想標籤是唯一的出路。謝謝。 –