https://kotlinlang.org logo
Title
a

Animesh

01/24/2019, 7:41 AM
Hey Guys, I am facing issue regarding mockito test case for coroutines. It is not executing api call function. Please have a look below code. It is MVP based structure //MVP Structure GlobalScope.launch { // API CALL ON MAIN THREAD val result = //Model return some values GlobalScope.launch(Dispatchers.Main) { when (result) { is APIResult.Success ->(result.response.data) is APIResult.Failure -> parseException(result.details) } } } } Any suggestion?
h

Hadi Tok

01/24/2019, 10:39 AM
it might be good to see the test code. Also if you add your code as code snipped it would be better.
a

Animesh

01/24/2019, 11:56 AM
Yes sure here is code snipped :
lateinit var meuralClient: MeuralAPIContract
    val deviceId = 7L
    val successScheduleApiResult = APIResult.Success(Schedule())

    @Before
    fun setUp() {
        view = mock()
        meuralClient = mock()
        model = CreateEventModel(mock(), meuralClient)
        device = mock()
        scheduleEvent = ScheduleEvent(0, null, null, null, null, null)
        presenter = CreateEventPresenter(view, model, scheduleEvent, mock(), mock(), mock(), mock())
    }


    @test
    fun verifyUpdateSchedule() {
        runBlocking {
            val newSchedule = Schedule()
            whenever(meuralClient.updateDeviceSchedule(deviceId, newSchedule))
                    .thenReturn(successScheduleApiResult)

            // We are facing an issue at this line.
            presenter.updateSchedule(true)
//            val result = model.updateSchedule(deviceId, newSchedule)
//            assert(result.value?.data == successScheduleApiResult.response.data)
        }
    }
--------------------------------
m

mvbrenes

01/26/2019, 2:56 PM
to properly snip your code you should add three grave accent marks: ` at the start and end of your code
h

Hadi Tok

01/26/2019, 7:20 PM
lol someone got
@test
user name and had a mention