小编sur*_*rga的帖子

没有 roboelectric 的模拟 android.os.BaseBundle

我正在尝试对此代码进行单元测试:

Bundle cidParam(String accountId) {
    Bundle params = new Bundle(1);
    params.putString(Params.CID, accountId);

    return params;
}
Run Code Online (Sandbox Code Playgroud)

这是单元测试:

private void mockBundle(String cid) throws Exception {
    Bundle mBundle = PowerMockito.mock(Bundle.class);
    PowerMockito.doNothing().when((BaseBundle)mBundle).putString(AnalyticsController.Params.CID, cid);
}
Run Code Online (Sandbox Code Playgroud)

但是,它总是返回:

java.lang.RuntimeException: Method putString in android.os.BaseBundle not mocked.
Run Code Online (Sandbox Code Playgroud)

我知道我可以使用 roboelectric 来启动模拟器并调用真实的包。然而,它会减慢单元测试的速度。有谁知道如何模拟 Android .os.base ?谢谢。

java android unit-testing mockito powermock

4
推荐指数
1
解决办法
6059
查看次数

Ambiguous type name in Swift unit test

Recently I spent quite some time to figure it out the issue with my unit test. The error that I saw in my unit test is :

Ambiguous type name 'AssetIdentifier' in 'UIImage'
Run Code Online (Sandbox Code Playgroud)

This is the complete code :

import XCTest
import module
@testable import module

class VoucherOptionsViewControllerTests: XCTestCase {
    lazy var result = ""

    class VoucherOptionsViewControllerMock: VoucherOptionsViewController {

        var result = ""

        override func showOverlayView(title: String, message: String, assetIdentifier: UIImage.AssetIdentifier) {
            self.result = "lalalala"
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

AssetIdentifier is …

unit-testing ios swift

1
推荐指数
1
解决办法
1224
查看次数

标签 统计

unit-testing ×2

android ×1

ios ×1

java ×1

mockito ×1

powermock ×1

swift ×1