Having this method: ``` fun setup() { if (...
# coroutines
a
Having this method:
Copy code
fun setup() {
        if (!requiresMigration()) {
            launch { regularPaymentSetup.setup() }
        } else {
            launch { migrationPaymentSetup.setup(it) }
        }
    }
How to unit-test that regularPayment is executed?
launch
starts a new coroutine and test fails
j
I'd always prefer creating suspending function, and only create coroutine at the most top-level.
1
💯 2
Copy code
suspend fun setup() {
	if (!requiresMigration()) {
		regularPaymentSetup.setup()
	} else {
		migrationPaymentSetup.setup(it)
	}
}
a
That’s my usual approach
j
And test sudently becomes easy
why cannot you apply it here?
a
Copy code
fun setup() {
        if (!requiresMigration()) {
            launch { regularPaymentSetup.setup() }
        } else {
            reactiveRxCache.load().subscribe {
                launch { migrationPaymentSetup.setup(it) }
            }

        }
    }
There is some Rx inside =(
j
Copy code
suspend fun setup() {
	if (!requiresMigration()) {
		regularPaymentSetup.setup()
	} else {
		reactiveRxCache.load().consumeEach {
			migrationPaymentSetup.setup(it)
		}
	}
}
using
kotlinx-coroutines-rx2
a
Thanks for the tip, I’ll take a look