Android Testing ViewModel - Common problems

Поделиться
HTML-код
  • Опубликовано: 7 ноя 2024

Комментарии • 24

  • @francotavares5448
    @francotavares5448 Год назад +2

    Conteúdo de primeira linha!! Tem pouquíssimo conteúdo por aí sobre testes no Android e vc me ajudou muito nesse vídeo, valeuu

  • @mouzinu
    @mouzinu Год назад +1

    Que vídeo bom mano!!! Por favor, faz uma série de test em android, tem pouquissimo conteúdo sobre.

  • @siddharthshah4220
    @siddharthshah4220 9 месяцев назад +1

    Amazing video! Thank you for explaining this.
    One doubt: So, if we move away from coroutines, livedata to something else, our Unit Tests needs to be changed as well. Aren't Unit tests suppose to be independent of the implementation details?

  • @andyli619
    @andyli619 Год назад +2

    great video great explaination of unit test. I learned a lot from this awesomevideo thank you bro!

    • @Renaro
      @Renaro  Год назад +1

      Happy to read this!

  • @brahianmartinez2270
    @brahianmartinez2270 Год назад +3

    bro, really thank you! finally made my viewmodel tests work, all I was missing was this dispatcher.scheduler.advanceUntilIdel() function before doing the assertions, thank you! new subscriber here!

    • @Renaro
      @Renaro  Год назад

      Happy to help! Subscribing would help the channel if you can :)

    • @brahianmartinez2270
      @brahianmartinez2270 Год назад

      @@Renaro yeah, already subscribed! :)

  • @firaszuriekat8341
    @firaszuriekat8341 2 года назад +2

    Great but could we use this dispatcher for Instrumented tests? I love to see AndroidTests (instrumented) tests. Very few example on that.

    • @Renaro
      @Renaro  2 года назад +1

      Hey Firas, for Instrumented tests you don't need it, you can mock the responses of your ViewModel. I will create a video about that!

    • @firaszuriekat8341
      @firaszuriekat8341 2 года назад +1

      @@Renaro So grateful. I know Mockk or Mockitp are there to help.

  • @philipjanbaruis7040
    @philipjanbaruis7040 Год назад

    Another treasure I just found.

  • @dragonzhao433
    @dragonzhao433 Год назад

    this only check for state change but how we verify the livedata changed with observer?

  • @thencode8403
    @thencode8403 Год назад

    I am having trouble testing cold flows. Stateflow create with stateIn function.
    I need to collect it first before I can check it new not initial value

  • @andrevini8099
    @andrevini8099 Год назад +1

    Hi, I am having a problem that my viewModel uses the function init{} and it is pointing that I Method getMainLooper in android.os.Looper not mocked. for this, any tips?

    • @Renaro
      @Renaro  Год назад +1

      I would recommend injecting a dispatcher as an argument to the viewModel, then you can easily replace it for a Test dispatcher for unit tests, see it here:
      developer.android.com/kotlin/coroutines/coroutines-best-practices

    • @andrevini8099
      @andrevini8099 Год назад +1

      @@Renaro Thank you very much Renaro, what I did was instantiate my view model inside my setup function after Dispatchers.setMain(dispatcher)

  • @jiegao-k3f
    @jiegao-k3f Год назад +1

    great video. I have learned more, You have another about Unit tests and UI tests can share me

  • @Klash1100
    @Klash1100 Год назад

    Dude, thank you!

  • @thencode8403
    @thencode8403 Год назад +1

    You're awesome ❤

  • @shaharts8333
    @shaharts8333 Месяц назад

  • @InimigoDaEscala6x1
    @InimigoDaEscala6x1 Год назад

    nice video, thanks

  • @thecreative9102
    @thecreative9102 Год назад +1

    A lot of boiler plate code to use observer in the test class, instead create a separate LiveDataUtil file

    • @Renaro
      @Renaro  Год назад +1

      Indeed that could help!