我有一个ListActivity它的适配器实现ViewHolder模式.
适配器和视图:
private class PlaceAdapter extends ArrayAdapter<PlaceModel> {
final int viewResourceId;
public PlaceAdapter(Context context, int textViewResourceId, List<PlaceModel> objects) {
super(context, textViewResourceId, objects);
viewResourceId = textViewResourceId;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
LayoutInflater inflater = getLayoutInflater();
convertView = inflater.inflate(viewResourceId, null);
holder = new ViewHolder(convertView);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
PlaceModel place = getItem(position);
holder.name.setText(place.getName());
holder.address.setText(place.getVicinity());
return convertView;
}
}
private class ViewHolder { …Run Code Online (Sandbox Code Playgroud) 我正在使用Android Studio.我有两个测试.一个扩展
import junit.framework.TestCase
Run Code Online (Sandbox Code Playgroud)
另一个
import android.test.ActivityInstrumentationTestCase2;
Run Code Online (Sandbox Code Playgroud)
第一个是从Android Studio和命令行运行的:
~/Software/android-studio/sdk/platform-tools/adb shell am instrument -w -r -e debug false com.gruszczy.eisenhower.test/android.test.InstrumentationTestRunner
INSTRUMENTATION_STATUS: numtests=1
INSTRUMENTATION_STATUS: stream=
com.gruszczy.eisenhower.test.TasksReconciliatorTest:
INSTRUMENTATION_STATUS: id=InstrumentationTestRunner
INSTRUMENTATION_STATUS: test=testRemoteInsert
INSTRUMENTATION_STATUS: class=com.gruszczy.eisenhower.test.TasksReconciliatorTest
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS_CODE: 1
INSTRUMENTATION_STATUS: numtests=1
INSTRUMENTATION_STATUS: stream=.
INSTRUMENTATION_STATUS: id=InstrumentationTestRunner
INSTRUMENTATION_STATUS: test=testRemoteInsert
INSTRUMENTATION_STATUS: class=com.gruszczy.eisenhower.test.TasksReconciliatorTest
INSTRUMENTATION_STATUS: current=1
INSTRUMENTATION_STATUS_CODE: 0
INSTRUMENTATION_RESULT: stream=
Test results for InstrumentationTestRunner=.
Time: 0.04
OK (1 test)
INSTRUMENTATION_CODE: -1
Run Code Online (Sandbox Code Playgroud)
但正如您所见,活动测试根本没有被调用.任何想法,我可能会失踪,让它运行?我的AndroidManifest instrumentTest目录:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gruszczy.eisenhower.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
<application>
<uses-library android:name="android.test.runner" …Run Code Online (Sandbox Code Playgroud) 嗨,我刚刚在roblectric测试案例中工作,我们可以使用@Ignore忽略测试用例我的问题是我们可以做什么Android单元测试案例的AndroidTestCase仪器项目,是 @Suppressandroid测试用例和Robolectric一样@Igore吗?请给我一些信息,我已经去过了
我正试图Activity在浓缩咖啡中推出.问题是我想把嘲笑的额外内容放到Intent我用来启动它的地方Activity.这是一个例子.
@RunWith(AndroidJUnit4.class)
public final class NiceActivityTester
{
@Rule
public final ActivityTestRule<NiceActivity> activityRule = new ActivityTestRule<>(NiceActivity.class, true, false);
@Test
public void justStartPlease() {
NiceThing niceThing = Mockito.mock(NiceThing.class);
Mockito.when(niceThing.getName()).thenReturn("Nice!");
Intent intent = new Intent(InstrumentationRegistry.getTargetContext(), NiceActivity.class);
intent.putExtra("NICE_THING", niceThing);
activityRule.launchActivity(intent);
}
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,解组Parcelable失败了.
java.lang.RuntimeException: Unable to start activity ComponentInfo{app.application/app.application.activity.NiceActivity}: android.os.BadParcelableException: ClassNotFoundException when unmarshalling: NiceThing_Proxy
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at …Run Code Online (Sandbox Code Playgroud) android unit-testing android-intent android-testing android-espresso
我现在正试图通过它的类及其文本来使Espresso与UIElement匹配,因为它目前没有资源ID(我知道,我知道......).我不确定这个的正确语法是什么,因为Espresso文档很模糊(我对此非常陌生并且编程一般,所以我确定我错过了一些东西).这是我到目前为止所拥有的:
onView(allOf(instanceOf(android.widget.CheckBox)), withText("S"))).
perform(scrollTo()).
check(matches(isChecked()));
Run Code Online (Sandbox Code Playgroud)
我尝试只输入"文本框",但在这两种情况下我都会收到"表达式预期"错误.截至目前,这是识别此元素的唯一方法,因此任何指针都会有所帮助.谢谢!
我正在尝试在我的android项目中使用Dagger2,如hitherejoe/Android-Boilerplate中所述.在我设置项目时,我在构建时遇到了错误.
Error:(30, 26) error: cannot find symbol variable DaggerTestComponent
Run Code Online (Sandbox Code Playgroud)
在深入研究文档和生成代码后,我发现代码不是在debug(/ app/build/generated/source/apt/debug /)文件夹中生成的,而是在test/debug中生成的(/ app/build/generated/source/apt/test/debug)文件夹.所以在我的测试源文件夹中无法导入生成的DaggerTestComponent.
任何线索如何将test/debug文件夹包含在源代码中?我的依赖如下
testCompile 'com.neenbedankt.gradle.plugins:android-apt:1.8'
compile "com.google.dagger:dagger:$DAGGER_VERSION"
apt "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
provided 'javax.annotation:jsr250-api:1.0'
compile 'javax.inject:javax.inject:1'
testApt "com.google.dagger:dagger-compiler:$DAGGER_VERSION"
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我想为我的Android应用创建测试。每当它失去焦点时,就应该采取措施。
因此,我想通过按2次“概述”按钮(“主页”按钮旁边的按钮)进行测试。但是,我该如何使用Espresso?我尝试了一些按键代码,但没有一个起作用(不幸的是,KEY_OVERVIEW表中没有)。
那么我该如何测试呢?
谢谢,
尼克拉斯
所以我最近在我的应用程序中添加了持久性并且我得到了这个错误,但有趣的部分是应用程序运行良好,即使持久化对象检索它们和一切,但在运行单元测试时我得到上面写的错误.
以下是我的应用程序的有趣部分
清单权限:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission." />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.READ_PROFILE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
Run Code Online (Sandbox Code Playgroud)
这是gradle配置defailtConfig块
compileSdkVersion 24
buildToolsVersion '25.0.0'
defaultConfig {
applicationId "mehungry.com.myapplicationnavigationdawerdemo"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
minSdkVersion 22
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled = true
jackOptions {
enabled true
}
}
Run Code Online (Sandbox Code Playgroud)
我的DatabaseHelper:
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DatabaseHelper extends SQLiteOpenHelper {
public static final int DATABASE_VERSION = 2; …Run Code Online (Sandbox Code Playgroud) 我用Espresso Recorder录制了浓缩咖啡测试。我想测试我的应用中的一些位置更改。
目前,我正在使用以下代码来模拟位置:
LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy( Criteria.ACCURACY_FINE );
String mocLocationProvider = LocationManager.GPS_PROVIDER;//lm.getBestProvider( criteria, true );
lm.addTestProvider(mocLocationProvider, false, false,
false, false, true, true, true, 0, 5);
lm.setTestProviderEnabled(mocLocationProvider, true);
Location loc = new Location(mocLocationProvider);
Location mockLocation = new Location(mocLocationProvider); // a string
mockLocation.setLatitude(-26.902038); // double
mockLocation.setLongitude(-48.671337);
mockLocation.setAltitude(loc.getAltitude());
mockLocation.setTime(System.currentTimeMillis());
mockLocation.setAccuracy(1);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
mockLocation.setElapsedRealtimeNanos(SystemClock.elapsedRealtimeNanos());
}
lm.setTestProviderLocation( mocLocationProvider, mockLocation);
Run Code Online (Sandbox Code Playgroud)
我还向调试清单文件添加了权限:
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION"/>
Run Code Online (Sandbox Code Playgroud)
但不幸的是,我仍然收到安全异常:
java.lang.SecurityException: mypackage.test from uid not allowed to perform MOCK_LOCATION
Run Code Online (Sandbox Code Playgroud)
我想使用Google Firebase测试实验室中的模拟位置来运行记录的测试用例。我怎么解决这个问题?
android android-location android-testing android-espresso firebase-test-lab
android ×10
android-testing ×10
unit-testing ×2
dagger-2 ×1
hamcrest ×1
kotlin ×1
robolectric ×1
spoon ×1
sqlite ×1