android - 使用junit在android的框架中测试业务逻辑
问题描述
我想为我的 android 应用程序编写单元测试用例,但我的业务逻辑在一个片段中。从我读到的最好将业务逻辑与android组件分开来进行单元测试。
这是我需要为其编写单元测试的功能:
private fun loadingProject(projectDetails: ProjectDetails, isOldValueNull:Boolean, isForceLoad: Boolean) {
if (projectDetails.Project == null)
return
projectDetails.Project!!.isGateway = !App.instance!!.isOnlineApp
if(Version(projectDetails.Project?.Version).isHigherThan("5")){
val path = Environment.getExternalStorageDirectory().absolutePath+"/"+App.instance!!.getString(R.string.app_name)+"/sList.json"
val bufferedReader = BufferedReader(FileReader(path))
val js = Gson().fromJson(bufferedReader, Sensor::class.java)
App.instance!!.info = js.Sensors
}
Project.saveProject(projectDetails.Project!!, isOldValueNull, isForceLoad)
if (projectDetails.Project!!.GatewayDeviceId == null) {
showAlert()
}
if (projectDetails.SerialNos != null) {
dType.remove(BeamItemTypes.SerialNos.name, App.instance!!.currentServerMode)
projectDetails.SerialNos?.mapIndexed { index, it ->
it.index = index
it.Type = BeamItemTypes.SerialNos.name
}
}
}
正如你所看到的,这是一个私有函数,它在一个片段中。测试这种功能的最佳方法是什么?
解决方案
推荐阅读
- html - 标题和导航栏之间的差距
- python - 使用python-docx时如何在表格单元格中列出多行?
- javascript - React Native 中的异步存储仅显示第一次保存的数据
- react-native - 我们可以将现有的 React Native 应用程序转换为 Flutter,而无需在 Flutter 中从头开始编写代码吗
- opengl - 在 Opengl 中修改 VBO 的最佳方法是什么?喜欢推流行吗?
- javascript - 禁用新日期时间的前 7 周并禁用日期选择器的周末
- mysql - Mysql JDBC getTimestamp 返回错误值
- python - 在 GCP 中使用 tensorflow_cloud 训练模型时如何引用自定义 Python 文件?
- python - 是否可以将 Tkinter 中的图像移到最后面?
- qt - QT 样式表中的混合背景颜色