Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用junit在android框架中测试业务逻辑_Android_Unit Testing_Kotlin_Junit - Fatal编程技术网

使用junit在android框架中测试业务逻辑

使用junit在android框架中测试业务逻辑,android,unit-testing,kotlin,junit,Android,Unit Testing,Kotlin,Junit,我想为我的android应用程序编写单元测试用例,但我的业务逻辑在一个片段中。 据我所知,最好将业务逻辑从android组件中分离出来进行单元测试 这是我需要为其编写单元测试的函数: private fun loadingProject(projectDetails: ProjectDetails, isOldValueNull:Boolean, isForceLoad: Boolean) { if (projectDetails.Project == null)

我想为我的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
            }
        }
    }
正如您所看到的,这是一个私有函数,它位于片段中。测试此类功能的最佳方法是什么?

您可以检查android,尤其是,您可以检查android,尤其是,