我正在尝试为记事本应用程序编写示例测试。在下面的代码中,我收到警告,我无法运行测试。请帮我解决这个问题。警告说“构造函数ActivityInstrumentationTestCase2<NotesList>(String, Class<NotesList>) is deprecated
”并且Eclipse中的执行在testAddNote();
处停止。如果您需要任何logcat日志,请恢复原状。
package com.example.android.notepad.test;
import com.example.android.notepad.*;
import com.jayway.android.robotium.solo.Solo;
import android.test.ActivityInstrumentationTestCase2;
import android.test.suitebuilder.annotation.*;
public class NotePadTest extends ActivityInstrumentationTestCase2<NotesList> {
private Solo solo;
public NotePadTest() {
super("com.example.android.notepad", NotesList.class);
}
@Override
public void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
}
@Smoke
public void testAddNote() throws Exception {
solo.clickOnButton(0);
//Assert that NoteEditor activity is opened
solo.assertCurrentActivity("Expected NoteEditor activity", "NoteEditor");
//In text field 0, add Note 1
solo.enterText(0, "Note 1");
solo.goBack();
//Clicks on menu item
solo.clickOnMenuItem("Add note");
//In text field 0, add Note 2
solo.enterText(0, "Note 2");
//Go back to first activity named "NotesList"
solo.goBackToActivity("NotesList");
boolean expected = true;
boolean actual = solo.searchText("Note 1") && solo.searchText("Note 2");
//Assert that Note 1 & Note 2 are found
assertEquals("Note 1 and/or Note 2 are not found", expected, actual);
}
@Override
public void tearDown() throws Exception {
//Robotium will finish all the activities that have been opened
solo.finishOpenedActivities();
}
}
这是StackTrace
java.lang.NoClassDefFoundError: com.jayway.android.robotium.solo.Solo
at com.example.android.notepad.test.NotePadTest.setUp(NotePadTest.java:37)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169)
at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154)
at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:537)
at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1551)
答案 0 :(得分:4)
“NoClassDefFoundError”是由于android sdk升级到版本17。我们需要在java build path中的“order and export”选项卡中检查robotium。但是我仍然可以找到构造函数弃用的warring的解决方案。
答案 1 :(得分:2)
我知道为时已晚。但它可能会帮助别人。 我也有同样的问题。我只通过在super。下编写类名来解决它。
而不是
super("com.example.android.notepad", NotesList.class);
只写
super(NotesList.class);
答案 2 :(得分:0)
可能是您使用低版本的robotium库,请将其更新为3.5
http://code.google.com/p/robotium/downloads/detail?name=robotium-solo-3.5.1.jar
注意: 您的项目 - &gt;单击鼠标右键 - > 属性 - &gt; Java构建路径 - &gt;选择标签库 - &gt;点击按钮添加JAR ... - &gt;浏览到robotium-solo-3.5.1.jar - &gt;点击按钮弹出确认
更改为标签订单和导出 - &gt;点击选择 robotium-solo-3.5.1.jar - &gt;行