【问题标题】:Unit Testing : Retrofit 2 Exception - API interfaces must not extend other interfaces单元测试:改造 2 异常 - API 接口不得扩展其他接口
【发布时间】:2021-01-21 14:39:58
【问题描述】:

我没有扩展任何接口,我所有的接口都是独立的。在执行单元测试时,我收到以下异常。在正常的 API 调用期间,一切正常。

 val retrofit: Retrofit = Retrofit.Builder()
            .baseUrl(url)
            .client(httpBuilder.build())
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .build()
        return retrofit.create(MyApi::class.java)

只有在执行单元测试时才会在retrofit.create(..) 引发异常。有没有办法避免这个错误?

【问题讨论】:

    标签: android mockito powermockito android-unit-testing


    【解决方案1】:

    这可以通过使用依赖注入在要测试的方法中获取服务而不是在方法中创建实例来解决。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-30
      • 2012-11-27
      相关资源
      最近更新 更多