Testing Navigation with Mockito & Espresso - Testing in Android - Part 13

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

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

  • @thomasknee7844
    @thomasknee7844 2 года назад

    Everytime I get stuck in my Android testing knowledge and I can't find what I'm looking for in the docs, I find a video by you and it helps answer most if not all of my questions, thank you, keep doing what you do :)

  • @Alchemist10241
    @Alchemist10241 3 года назад +3

    I was looking for a way to test navigations for a long time and this video explains how to do it in a simplistic manner. Philipp YOU ARE THE BEST 😎. By the way to create a new test class from a class (or switch to an existing test class) just use CTRL + SHIFT + T shortcut key. Thanks a lot.

  • @matt-g-recovers
    @matt-g-recovers 3 года назад +2

    Love it.
    After this bit, I will be extremely comfortable with every aspect of modern professional Android development...
    I mean shit I have been doing it since Eclipse in 2009, MVC. SQLiteOpenhelper, crashes, crashes, ANRs.... lol.
    Things have come a long way, I can't wait to see how Compose goes!!!
    (I put off testing for too long really was the issue why as a Sr developer I am just doing this, I love testing now though )

  • @dmytrodolotov9723
    @dmytrodolotov9723 10 месяцев назад

    Hi everyone, I've got SecurityException: Writing DEX files are not allowed, when trying to call Mockito's mock() function for navController. Look's like it only happens on Android 14. Any suggestions?

  • @ioannistzavaras6873
    @ioannistzavaras6873 3 года назад +1

    Thank you so much, Philipp! Great job! Keep going!

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

    @Phillipp Thanks for this awesome video.
    But how are you able to test on backPressed from Fragment2 in isolation with Fragment1?

  • @samalgerie25
    @samalgerie25 2 года назад

    I have an unrelated question. at 3:30 Phillip used the floating button (fabAddShoppingItem.setOnCli...) without using binding or even findById. Does anyone know how he could do this?

    • @daniboy943
      @daniboy943 2 года назад

      The way he did is deprecated now. Stick to view binding and you'll be fine.

  • @akashdeepwadhwa5828
    @akashdeepwadhwa5828 3 года назад

    thank you very much ... for tutorials learnt a lot from you .. i have question after finishing this series..which project from your website i should learn ..to atleast get the job ..

  • @panspost609
    @panspost609 4 года назад

    since the android studio has the espresso recorder, why not use that recorder to do all those tests automatically?

  • @muhammadsarimmehdi
    @muhammadsarimmehdi 2 года назад

    how would you use this with databinding?

  • @ardinalbts3330
    @ardinalbts3330 2 года назад

    thank you sir.. great explanation

  • @junecnol79
    @junecnol79 3 года назад

    awesome tutorials. thank you again

  • @tochukwuokey-munonye7884
    @tochukwuokey-munonye7884 4 года назад +2

    I did the first test but the test for empty curImageUrl is difficult. Someone please help me

    • @ochornmapromise257
      @ochornmapromise257 3 года назад +3

      @Test
      fun pressBackButton_imageUrlSetToEmptyString(){
      val testViewModel = ShoppingViewModel(FakeShoppingRepository())
      val navController = mock(NavController::class.java)
      launchFragmentInHiltContainer {
      Navigation.setViewNavController(requireView(), navController)
      viewModel = testViewModel
      }
      pressBack()
      val value = testViewModel.curImageUrl.getOrAwaitValue()
      assertThat(value).isEmpty()
      }

  • @quangtruongpham4057
    @quangtruongpham4057 4 года назад

    your tutorial is very helpful . Nice

  • @hellosagar
    @hellosagar 4 года назад

    Awesome Video

  • @foivosstamopoulos9709
    @foivosstamopoulos9709 4 года назад

    Great tutor!! Thank you!!

  • @chuka_obi5167
    @chuka_obi5167 3 года назад

    Thanks for your video Phillip! I learnt a lot from it. How do you test navigation if you have nav args? Would anyvalue work in the navdirections action?

    • @PhilippLackner
      @PhilippLackner  3 года назад +1

      The same way, just check that the navigate function was called with the right parameters

    • @chuka_obi5167
      @chuka_obi5167 3 года назад

      @@PhilippLackner Thank you. Will Try that out this night

  • @IdaBagusTrisnaWidia
    @IdaBagusTrisnaWidia 3 года назад

    I tried but failed. Is that caused by using viewbinding? You're using syntetic which is going to be deprecated

    • @akashdeepwadhwa5828
      @akashdeepwadhwa5828 3 года назад +1

      just override oncreate view and return binding.root from there

  • @baselnat93
    @baselnat93 3 года назад

    big thanks

  • @mustafaammar551
    @mustafaammar551 3 года назад

    Thank you Bro

  • @dmytromarchuk3023
    @dmytromarchuk3023 3 года назад

    thank you

  • @bhavyasharma3500
    @bhavyasharma3500 4 года назад

    Thanks man

    • @saumilpatel2480
      @saumilpatel2480 4 года назад

      How to test null URL? Have you tried?

    • @pavesid
      @pavesid 4 года назад +2

      ​@@saumilpatel2480 In launchFragment... get reference to viewModel.currentImageUrl, after pressBack() get url using getOrAwaitValue() and then compare with "".

    • @saumilpatel2480
      @saumilpatel2480 4 года назад

      ​@@pavesid Can you please put down the code, seems easy but i'm lost. Thank you

    • @karimabdelhameed2418
      @karimabdelhameed2418 4 года назад +2

      @@saumilpatel2480 : Hello , Hope this will help you my friend ideone.com/WvAofp , please try it and give me ur feedback, as I'm still not good at testing.

    • @karimabdelhameed2418
      @karimabdelhameed2418 4 года назад +1

      @@saumilpatel2480 Edit : I think it was wrong to assign/use the real viewModel instance, and we should use a fakeViewModel like this : ideone.com/UInCNT , I think if u saw the next videos , u will realize this by yourself, hope my answer helped u man!

  • @dmytromarchuk3023
    @dmytromarchuk3023 3 года назад

    Who is that man who is constantly putting a dislike on every video? :) It's gonna be your hater

  • @antoniokomangyudistira4150
    @antoniokomangyudistira4150 4 года назад

    Second

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

    Everytime I am getting this error while testing navigation for ShoppingFragment.
    java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState
    Can anyone please help ???

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

      Any one if facing the same issue with your device , please keep the device unlocked.

  • @siavashparsa5046
    @siavashparsa5046 3 года назад

    java.lang.AbstractMethodError: abstract method "java.util.List org.mockito.invocation.Invocation.getArgumentsAsMatchers()"
    i got this error would you please help me to solve this?

    • @ahmedfahimfoysaleishon2097
      @ahmedfahimfoysaleishon2097 3 года назад

      You have to remove the following
      androidTestImplementation "com.linkedin.dexmaker:dexmaker-mockito:2.12.1"
      androidTestImplementation "org.mockito:mockito-core:3.9.0"
      and add
      androidTestImplementation "org.mockito:mockito-android:3.9.0"

    • @dalimhmd
      @dalimhmd 3 года назад

      @@ahmedfahimfoysaleishon2097 Thanks very much bro, this totally works!

    • @brunonunes6532
      @brunonunes6532 8 месяцев назад +1

      @@ahmedfahimfoysaleishon2097 probably you dont remenber haha, but this comment saved a lot of my time, thnx bro!

    • @ahmedfahimfoysaleishon2097
      @ahmedfahimfoysaleishon2097 8 месяцев назад

      @@brunonunes6532 True, I don't remember I left a comment here ;D

  • @tochukwuokey-munonye7884
    @tochukwuokey-munonye7884 4 года назад +4

    I did the first test but the test for empty curImageUrl is difficult. Someone please help me