Java 尝试断言列表中文本视图的数量时,断言失败
当我试图断言列表中文本视图的数量时,为什么断言失败Java 尝试断言列表中文本视图的数量时,断言失败,java,android,robotium,Java,Android,Robotium,当我试图断言列表中文本视图的数量时,为什么断言失败 @Test public void testDeleteNote() throws Exception { int count= getNoOfTextViews(); // Checking if count is greater than 0. if (count > 0) { // Iterating count times for (int i = 0; i < cou
@Test
public void testDeleteNote() throws Exception {
int count= getNoOfTextViews();
// Checking if count is greater than 0.
if (count > 0) {
// Iterating count times
for (int i = 0; i < count; i++)
{
// Checking if count is even or odd.
if (i % 2 == 0) {
solo.clickInList(0);
deleteNote();
} else {
// Clicking Long on the 1st item in the Notes List.
solo.clickLongInList(0);
// Clicking on Delete String.
solo.clickOnText(solo.getString(R.string.menu_delete));
}
}
count = getNoOfTextViews();
// Asserting all the text views are deleted.
assertEquals(0, count);
}
public int getNoOfTextViews() {
// Getting the count of text views in the activity.
ArrayList<TextView> textView = solo.getCurrentViews(TextView.class,
solo.getCurrentViews(ListView.class).get(0));
return textView.size();
}
我看到的失败是:
junit.framework.AssertionFailedError:应为:但为:
更新:
我在调试时看到这一点,只有在运行测试用例时才会失败。您的count变量在程序开始时计算一次,然后再也不会更新。这意味着,当您在最后将其与0进行比较时,它仍然包含旧值
您只需再次调用该方法来更新count变量:
count = getNoOfTextViews();
或者干脆
assertEquals(0, getNoOfTextViews());
在计数之前添加了等待列表视图。这帮我解决了这个问题 谢谢大家
public int getNoOfTextViews() {
solo.waitForView(ListView.class,0,1000);
// Getting the count of text views in the activity.
ArrayList<TextView> textView = solo.getCurrentViews(TextView.class,
solo.getCurrentViews(ListView.class).get(0));
return textView.size();
}
我的错误我抄错了。我使用的是assertEquals0,getNoOfTextViews。此案例在我调试时通过,在我运行时失败。请添加更多代码。我们不知道什么是变量solo,什么是方法deleteNote、clickInList、clickLongInList和ClickContext。我们可以通过添加等待列表视图来解决这个问题。