Java 无法为android运行浓缩咖啡测试
我在为android设置/运行浓缩咖啡测试时遇到一些问题。 我的TestClass如下所示:-Java 无法为android运行浓缩咖啡测试,java,android,junit,junit3,android-espresso,Java,Android,Junit,Junit3,Android Espresso,我在为android设置/运行浓缩咖啡测试时遇到一些问题。 我的TestClass如下所示:- import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView; import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.click; import static com.google.andr
import static com.google.android.apps.common.testing.ui.espresso.Espresso.onView;
import static com.google.android.apps.common.testing.ui.espresso.action.ViewActions.click;
import static com.google.android.apps.common.testing.ui.espresso.assertion.ViewAssertions.matches;
import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId;
import static com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText;
import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
import com.sample.rasmus.MainActivity;
public class BasicTest extends ActivityInstrumentationTestCase2<MainActivity> {
public BasicTest(String name) {
super(MainActivity.class);
Log.v("amtesting","2");
}
@Override
public void setUp() throws Exception {
Log.v("amtesting","5");
super.setUp();
Log.v("amtesting","4");
// Espresso will not launch our activity for us, we must launch it via getActivity().
getActivity();
}
public void testSimpleClickAndCheckText(){
Log.v("amtesting","1");
onView(withId(com.sample.rasmus.R.id.thebutton)).perform(click());
onView(withId(com.sample.rasmus.R.id.helloworld)).check(matches(withText("awesome")));
}
protected void tearDown() throws Exception {
Log.v("amtesting","3");
super.tearDown();
}
}
导入静态com.google.android.apps.common.testing.ui.espresso.espresso.onView;
导入静态com.google.android.apps.common.testing.ui.espresso.action.ViewActions.click;
导入静态com.google.android.apps.common.testing.ui.espresso.assertion.viewsassertions.matches;
导入静态com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withId;
导入静态com.google.android.apps.common.testing.ui.espresso.matcher.ViewMatchers.withText;
导入android.test.ActivityInstrumentationTestCase2;
导入android.util.Log;
导入com.sample.rasmus.main活动;
公共类基本测试扩展了ActivityInstrumentationTestCase2{
公共基本测试(字符串名称){
超级(MainActivity.class);
Log.v(“amtesting”,“2”);
}
@凌驾
public void setUp()引发异常{
Log.v(“amtesting”、“5”);
super.setUp();
Log.v(“amtesting”,“4”);
//Espresso不会为我们启动活动,我们必须通过getActivity()启动活动。
getActivity();
}
public void testSimpleClickAndCheckText(){
Log.v(“amtesting”,“1”);
onView(使用id(com.sample.rasmus.R.id.thebutton)).perform(单击());
onView(withId(com.sample.rasmus.R.id.helloworld)).check(匹配项(withText(“awesome”));
}
受保护的void tearDown()引发异常{
Log.v(“amtesting”,“3”);
super.tearDown();
}
}
AndroidManifest.xml如下所示:-
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sample.rasmus.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="14" />
<instrumentation
android:name="com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner"
android:targetPackage="com.sample.rasmus" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<uses-library android:name="android.test.runner" />
</application>
</manifest>
运行配置已经更新,使用Google InGoogleInstrumentationTestRunner
作为InstrumentationRunner
但是,当我运行测试时,它会在控制台上为我提供以下信息:-
- 在设备emulator-5554上启动instrumentation android.test.InstrumentationTestRunner
- 向Eclipse发送测试信息
- 测试完成
没有提到运行测试,测试也不会运行。我会错过什么呢?好的,这就是我最终解决问题的方法。我将测试类的构造函数更改为:-
public BasicTest() {
super(MainActivity.class);
}
它开始工作了。奇怪的是,这就是让我忙了一整天的原因