放置在 android.util.SparseArray 中的方法未模拟

     2023-02-19     17

关键词:

【中文标题】放置在 android.util.SparseArray 中的方法未模拟【英文标题】:Method put in android.util.SparseArray not mocked 【发布时间】:2020-05-24 04:23:47 【问题描述】:

我想运行一个包含此代码的测试:

    @Test
    public void deleteItemWithKeyGreaterThenTest() 
        SparseArray<String> sparseArray = new SparseArray<String>();
        sparseArray.put(0, "zero");

但是当我运行测试时,我得到:

java.lang.RuntimeException: Method put in android.util.SparseArray not mocked.

我已经阅读了这个Unit testing ArrayMap throws Method put in android.util.ArrayMap not mocked,但它没有提供明确的解决方案。

你能告诉我我做错了什么吗?

提前谢谢你!

编辑:完整代码

import org.junit.Test;

import static org.junit.Assert.*;

import android.util.SparseArray;

@Test
public void deleteItemWithKeyGreaterThenTest() 
    SparseArray<String> sparseArray = new SparseArray<String>();
    sparseArray.put(0, "zero");
    assertEquals(sparseArray.size(), 1);

两个都试过了:

android 
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig 
        applicationId "com.example.navmaze"
        minSdkVersion 15
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    
    buildTypes 
        release 
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        
    
    testOptions 
        unitTests.returnDefaultValues = true
        unitTests.includeAndroidResources = true
    

android 
    compileSdkVersion 29
    buildToolsVersion "29.0.2"
    defaultConfig 
        applicationId "com.example.navmaze"
        minSdkVersion 15
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    
    buildTypes 
        release 
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        
    

这些是我的依赖项:

dependencies 
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    testImplementation 'junit:junit:4.12'
    testImplementation 'androidx.test:core:1.2.0'
    testImplementation 'org.mockito:mockito-core:1.10.19'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'org.jetbrains:annotations-java5:15.0'

【问题讨论】:

你没有做错什么,android开发是一团糟。是否按照此处的建议清除您的 Maven 存储库:github.com/robolectric/robolectric/issues/4740? 我没有任何要清理的 Maven 存储库... 好吧!我想不是这样的。 =/ 你能发布你的依赖部分/模拟配置吗? 我添加了一些信息。 【参考方案1】:

根据此文档unitTest,在测试中,Android 包似乎只是一个“空”实现。

【讨论】:

创建多个放置在彼此之上的可放置同级

】创建多个放置在彼此之上的可放置同级【英文标题】:Creatingmultipledroppablesiblingsthatatpositionedontopofeachother【发布时间】:2012-09-2507:39:47【问题描述】:我正在尝试创建多个彼此相邻的jquery可放置对象,其中某些部分可能会重叠... 查看详情

如何从放置在 UIAlertController 上的 UITextField 处理程序访问放置在 UIAlertController 上的按钮?

】如何从放置在UIAlertController上的UITextField处理程序访问放置在UIAlertController上的按钮?【英文标题】:HowtogetaccesstobuttonplacedonUIAlertControllerfromhandlerofUITextFieldplacedonUIAlertController?【发布时间】:2016-10-0214:25:11【问题描述】:我使... 查看详情

Sencha Touch - 在面板中水平放置而不是垂直放置的标签

】SenchaTouch-在面板中水平放置而不是垂直放置的标签【英文标题】:SenchaTouch-Labelshorizontallyplacedinsteadofverticallyinapanel【发布时间】:2011-12-0515:31:47【问题描述】:我想在垂直布局中放置两个标签、一个文本字段和一个按钮。但是... 查看详情

启动 jQuery 脚本在放置在控制台时有效,但在放置到站点代码时无效

】启动jQuery脚本在放置在控制台时有效,但在放置到站点代码时无效【英文标题】:InitiatingjQueryscriptworkswhenplacedinconsolebutnotwhenplacedintositecode【发布时间】:2020-02-0217:43:17【问题描述】:我有一些代码可以简单地打开一个框,复... 查看详情

如何在放置事件jquery上获取放置项目的ID

】如何在放置事件jquery上获取放置项目的ID【英文标题】:Howtogetthedroppeditem\'sidondropeventjquery【发布时间】:2011-09-1015:00:26【问题描述】:当我将某些东西拖放到jquerydroppable时,我想获取被删除项目的id。当我这样做时:$("#here").d... 查看详情

UIAlertView,如何在里面放置很多按钮?

】UIAlertView,如何在里面放置很多按钮?【英文标题】:UIAlertView,howtoplacealotofbuttonsinsideit?【发布时间】:2011-09-2615:54:01【问题描述】:在UIAlertView中,如何在其中放置大量按钮?我有一个警报视图,想在其中放置十个按钮,但是... 查看详情

如何将 UILabel 放置在 UIImageView 下方,使其始终均匀放置

】如何将UILabel放置在UIImageView下方,使其始终均匀放置【英文标题】:HowcanIplaceaUILabelbelowanUIImageViewsuchthatitisalwaysevenlyplaced【发布时间】:2016-08-2907:00:25【问题描述】:我制作了一个看起来像这样的自定义弹出视图我想将用户名... 查看详情

在结果集中放置一个联合查询

】在结果集中放置一个联合查询【英文标题】:PlacingaUnionqueryintheresultset【发布时间】:2011-12-1202:26:17【问题描述】:任何人都可以建议是否有任何规则可以在jdbc结果集中放置联合查询?我在数据库中有一个联合查询,我得到了... 查看详情

如何在圆圈边缘放置图标

】如何在圆圈边缘放置图标【英文标题】:Howtoplaceiconsattheedgeofcircle【发布时间】:2021-06-2923:12:11【问题描述】:我想将图标放置在其父级(圆圈)的边缘,如下所示:我尝试了一些方法,但默认绝对子级放置在其父级的起始位... 查看详情

在图片下方放置链接

】在图片下方放置链接【英文标题】:Puttingalinkbelowanimage【发布时间】:2021-12-0516:08:27【问题描述】:我正在尝试在图片下方放置一个链接,无论出于何种原因,该链接一直在图片的一侧(右侧)。图片显示正常,链接有效,但... 查看详情

为啥在包含警卫之前放置#include

】为啥在包含警卫之前放置#include【英文标题】:WhyPlacing#includeBEFOREincludeguards为什么在包含警卫之前放置#include【发布时间】:2014-05-1910:37:05【问题描述】:在头文件中的包含保护之前放置#include指令是否有任何正当理由:#include... 查看详情

如何在 React JS 中将组件放置在模态的两端? [复制]

】如何在ReactJS中将组件放置在模态的两端?[复制]【英文标题】:HowtoplacecomponentsontwoendsofamodalinReactJS?[duplicate]【发布时间】:2020-10-0811:29:27【问题描述】:我想将我的两个组件放置一个开关切换和一个按钮在模态的两端。我可... 查看详情

我们如何在可放置 div 中释放项目的确切位置元素上放置

】我们如何在可放置div中释放项目的确切位置元素上放置【英文标题】:Howcanwedroponexactpositionelementwherewereleasetheitemindroppablediv【发布时间】:2018-09-2623:48:02【问题描述】:我正在研究拖放功能,它运行良好,但是当我拖放元素时... 查看详情

seaborn将图例放置在图像外部并使用move_legend函数将图例(legend)放置在图像的顶部且单行展开显示

seaborn将图例放置在图像外部并使用move_legend函数将图例(legend)放置在图像的顶部、且单行展开显示目录seaborn将图例放置在图像外部并使用move_legend函数将图例(legend)放置在图像的顶部并单行展开显示 查看详情

seaborn将图例放置在图像外部并使用move_legend函数将图例(legend)放置在图像的顶部top(多组图例)

seaborn将图例放置在图像外部并使用move_legend函数将图例(legend)放置在图像的顶部top(多组图例)目录seaborn将图例放置在图像外部并使用move_legend函数将图例(legend)将图例放置在图像的顶部(多组图例) 查看详情

在情节提要中将视图水平居中并垂直放置在底部

】在情节提要中将视图水平居中并垂直放置在底部【英文标题】:positionaviewhorizontallycenterandverticallyatbottominstoryboard【发布时间】:2016-01-1903:23:27【问题描述】:我有一个在故事板中有子视图的容器视图我想将容器视图水平放置... 查看详情

如何在堆栈中将文本放置在图像上?

】如何在堆栈中将文本放置在图像上?【英文标题】:HowcanIpositiontextoverimageeachotherinastack?【发布时间】:2020-10-1814:58:09【问题描述】:我一直在尝试在颤动中创建一张小卡片,并且我一直在尝试掌握堆栈的窍门以及如何将物品... 查看详情

如何在 ScrollView 内的 LinearLayout 底部放置按钮

】如何在ScrollView内的LinearLayout底部放置按钮【英文标题】:HowtoplacebuttonatthebottomofLinearLayoutwithinaScrollView【发布时间】:2020-11-0908:40:51【问题描述】:我创建了一个addview(xml)。当我按下添加按钮时,它会在LinearLayout中创建一个新... 查看详情