我创建测试项目。我的步骤:
完成后,我创建了libs文件夹并添加了espresso-1.0-SNAPSHOT-bundled.jar。项目的结构看起来
完成后,我创建了测试类:
public class TestT extends ActivityInstrumentationTestCase2<MainActivity>
{
public TestT(Class<MainActivity> activityClass)
{
super(activityClass);
}
@BeforeClass
public static void setUpBeforeClass() throws Exception
{}
@AfterClass
public static void tearDownAfterClass() throws Exception
{}
@Before
public void setUp() throws Exception
{}
@After
public void tearDown() throws Exception
{}
@Test
public void test()
{
fail("Not yet implemented");
}
@SmallTest
public void testTest()
{
Espresso.onView(ViewMatchers.withId(R.id.btnClick)).perform(ViewActions.click());
Espresso.onView(ViewMatchers.withId(R.id.tvClick)).check(ViewAssertions.matches(ViewMatchers.withText(MainActivity.TEXT)));
}
}
完成,我运行测试项目:
项目正在运行,但它不是任何显示。
我打开Window - Show View - Java - JUnit:
双击emulator-5554 show me对话框:
我尝试使用所有版本的Eclipse和ADT插件。我做错了什么?
答案 0 :(得分:1)
您正在使用JUnit 4.您必须使用JUnit 3,因为Espresso基于Android Instrumentation,目前仅支持JUnit 3.要执行此操作:
实施例: 不正确
@Test public void test() { fail("Not yet implemented"); }
实施例: 正确
public void test() { fail("Not yet implemented"); }
答案 1 :(得分:0)
您需要使用GoogleInstrumentationTestRunner。请参阅此处的说明:https://code.google.com/p/android-test-kit/wiki/Espresso#Espresso_Setup_Instructions
另外,将测试类构造函数更改为:
public TestT()
{
super(MainActivity.class);
}