简体   繁体   English

我如何在 Observable RxJava 中测试参数

[英]How I can test arguments in Observable RxJava

I have some method:我有一些方法:

repository.get(arg1, arg2, arg3)

Method return Single<List<SomeObject>>方法返回Single<List<SomeObject>>

I need testing that Single was called onSubscribe() with specific arguments.我需要测试的是单个被称为onSubscribe()与特定的参数。

repository.get(arg1, arg2, arg3)
            .test()
            .assertSubscribed()

This method ignores arguments which I put in method repository.get() .此方法忽略我放在方法repository.get()

How I can test that subscribe called with certain arguments?我如何测试使用某些参数调用的订阅?

use Schedulers.trampoline() to make the subscription occur on the current thread.使用Schedulers.trampoline()使订阅发生在当前线程上。 then you can assert the required args然后你可以断言所需的参数

@Before
    fun setup() {
        RxJavaPlugins.setIoSchedulerHandler { Schedulers.trampoline() }
        RxJavaPlugins.setComputationSchedulerHandler { Schedulers.trampoline() }
    }

this makes the code run on the current thread.这使得代码在当前线程上运行。 then you can assert the args然后你可以断言args

repository.get(arg1, arg2, arg3)
            .test()
            .subscribe {
                 // do the assertions here
             }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将 rxjava2 Zip function (从 Single/Observable)的 arity 推广到 n 可空 arguments 而不会丢失其类型? - How can I generalize the arity of rxjava2 Zip function (from Single/Observable) to n Nullable arguments without lose its types? 如何将 rxjava2 Zip function (从 Single/Observable)的 arity 推广到 n 可选 arguments 而不会丢失其类型? - How can I generalize the arity of rxjava2 Zip function (from Single/Observable) to n Optional arguments without lose its types? RxJava:如何重置长时间运行的热可观察链? - RxJava: How can I reset a long running hot observable chain? 我怎样才能停止观察一个 observable 而不在 RxJava2 中处理它? - How can I stop observing an observable without disposing it in RxJava2? 如何返回一个RxJava Observable,保证不会抛出OnErrorNotImplementedException? - How can I return an RxJava Observable which is guaranteed not to throw OnErrorNotImplementedException? 如何测试此rxJava代码? - How can I test this rxJava code? RxJava 测试 Observable - RxJava test Observable 如何在单元测试中处理模拟的 RxJava2 可观察抛出异常 - How to handle mocked RxJava2 observable throwing exception in unit test RxJava:如何单元测试 Observable 在正确的调度程序上被观察和订阅? - RxJava: How to unit test that an Observable is observed on and subscribed on the right scheduler? 在返回订阅服务器之前,如何拦截可观察对象并在RxJava中修改它? - How can I intercept an observable object and modify it in RxJava before returning to Subscriber?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM