Android Testing Repository - MVVM Unit Testing Tutorial | CheezyCode - Hindi

  Рет қаралды 7,312

Cheezy Code

Cheezy Code

Жыл бұрын

Learn Android Unit Testing - Learn how to unit test repository in Android MVVM Architecture. Learn how to use Mockito to mock different objects and define behavior using Mockito.when. Mocking objects help define canned responses for your functions. You can have pre-defined behavior for your methods that can help to write unit tests that are isolated from its collaborators. Learn how to define unit test cases for repository with different API responses.
Learn how to share code between test and androidtest directory in android using sourcesets in build.gradle file. Defining a common location that is accessible from both test directory can help share the code.
In this tutorial, we have covered Mockito, JUnit testing in Android. Learn unit testing in Android with simple examples in Kotlin Hindi. Everything is explained in Hindi (हिन्दी)
Topics covered -
1. Complete MVVM Architecture Example Walkthrough
2. Unit Test Case Setup using Mockito Mocking
3. Android Repository Unit Testing Simple Example
4. Sharing code between unit tests and instrumentation tests on android
5. Android JUnit Test Cases
Kotlin Flows Playlist -
• Kotlin Flows Tutorials
Jetpack Paging Tutorial -
• Android Paging 3 | Jet...
Complete Dependency Injection Playlist Link -
• Dagger 2 - Dependency ...
Complete Android Architecture Components Playlist -
• Android Architecture C...
Beginner series in Android Playlist (Hindi) -
• Android Tutorials Step...
Kotlin Beginners Tutorial Series -
• Kotlin Beginner Tutori...
For more info - visit the below link
www.cheezycode.com
We are social. Follow us at -
Facebook - / cheezycode
Twitter - / cheezycode
Instagram - / cheezycode

Пікірлер: 30
@manusarangal449
@manusarangal449 5 ай бұрын
Beautifully explained!
@rajayendluri5793
@rajayendluri5793 8 ай бұрын
00:01 Summary of Repository Code 00:58 Writing test cases and defining behaviour 03:24 How to define and run a test case 04:36 Testing with expected size 06:20 Handling error messages in repository 07:34 Discussing test cases and unit testing 09:06 Defining and testing Android functionalities 10:20 Creating common code for multiple classes
@rishikeshsingh9946
@rishikeshsingh9946 Жыл бұрын
Awesome hole series sir.❤️❤️
@CheezyCode
@CheezyCode Жыл бұрын
♥♥
@manojdas9590
@manojdas9590 Жыл бұрын
Please explain more about the share test. Please show at least one example
@BtrmaAbhishekVerma
@BtrmaAbhishekVerma 2 ай бұрын
how to test function that it set loader first and set result at last when it get result from api.
@tinkusony90
@tinkusony90 Жыл бұрын
Thanks sir 🙏🙏🙏
@CheezyCode
@CheezyCode Жыл бұрын
Most welcome
@shivanipaswan5657
@shivanipaswan5657 10 ай бұрын
Hey need more videos related to test cases with hilt really I'm too confused😵
@VishnuMangalasseri
@VishnuMangalasseri Жыл бұрын
Sir, if our viewmodel/repository have using common “object”(singletone) how can we add this to testcases, for example from datastore we are fetching one id and that id we are caling into api. How can we write test case for this.
@CheezyCode
@CheezyCode Жыл бұрын
Unit nahi h iss case mei ye....as a unit ek cheez he test hogi
@siddarthjain3959
@siddarthjain3959 Жыл бұрын
What's the purpose of testing when we already know what the function will return and then checking whether the function is returning the same or not (that we already mentioned) Humne test mai API calls ko check kra Phele humne empty list return krwai or fir baad mai khud hi check kiya k empty hai k nhi. Can you please tell like where this test will be useful?
@CheezyCode
@CheezyCode Жыл бұрын
Yes...ek example lete hai... repository mei ye function hai getProducts ke naam se...ab suppose isme hum log kuch filter kar rahe hote ki sirf 20$ se mehnge products chaiye ya suppose color pe filter hota...uske baad suppose map karte ki data format karle.... price rupees mei aaya hai toh usko convert karna h dollar mei Iss tareeke se suppose poora logic hota - ussi ke basis pe test cases likh dete...ab thode din baad requirement aati ki iss function mei aur changes karne hai...toh logic change hota iss function ka...ab ye jo existing test cases h either wo break nahi hone chaiye aur break hogaye toh matlab logic mei gadbad hai...to logic correct karege before committing. Hope clear hua hoga...
@CheezyCode
@CheezyCode Жыл бұрын
Ek aur perspective - suppose mock karke jitni bhi possibilities hum log soch skte the uske according test case likh dete but agar hamara mei code mei proper handling nahi hoti toh hume code modify karna hota...TDD mei aise he karte hai... incrementally implement karte hai function...we first think of a scenario then write test case for it - then implement it.
@bigguy8381
@bigguy8381 Жыл бұрын
@@CheezyCode so, should we write test cases for every functionality??
@vinaykumarmj
@vinaykumarmj Жыл бұрын
4:52 Is this good practice to add multiple Assert in one test case?
@CheezyCode
@CheezyCode Жыл бұрын
Yes we can keep the related asserts in one unit test
@PiyushSharma-gw1wx
@PiyushSharma-gw1wx Жыл бұрын
sir please make a series on jetpack compose for building UI.
@CheezyCode
@CheezyCode Жыл бұрын
naye saal pe - naye videos ke saath koshish karte h
@PiyushSharma-gw1wx
@PiyushSharma-gw1wx Жыл бұрын
@@CheezyCode Looking forward to it sir 👍
@aniketnath9381
@aniketnath9381 6 ай бұрын
I am getting the following error when I am trying to run my test cases. How may I fix it? Execution failed for task ':app:kaptGenerateStubsDebugUnitTestKotlin'. > Error while evaluating property 'filteredArgumentsMap' of task ':app:kaptGenerateStubsDebugUnitTestKotlin'. > Could not resolve all files for configuration ':app:debugUnitTestCompileClasspath'. > Could not find org.mockito.kotlin:mockito-kotlin:2.2.0. Required by: project :app
@saddam926
@saddam926 Жыл бұрын
it it it me- ye song hame chahiya...aap प्रबंध kijiye
@CheezyCode
@CheezyCode 11 ай бұрын
Prabandh ho rkha hai...bas recording studio mei jaake record karna baaki hai
@saddam926
@saddam926 11 ай бұрын
@@CheezyCode शिघ्र kijiye... विलम्ब nahi chalega....& Thanks for reply
@utkarshkumar1080
@utkarshkumar1080 Жыл бұрын
Sir you tell about sharedTest ,I successfully implemented it but when i am trying to access sharedtest from androidTest directory classes then android studio is not giving suggestion for shared class and showing red error but when i run the test with red error it compile and tested successfully(I am not getting error in test directory classes) ,still android studio is showing red error , Sir how to fix it ? Android studio is showing this warning = Duplicate content roots detected: Path [D:/System/Android Studio Projects/Testinginandroid/app/src/sharedTest/java] of module [Testing_in_android.app.unitTest] was removed from modules [Testing_in_android.app.androidTest]
@CheezyCode
@CheezyCode Жыл бұрын
Let me check - will reply it to you soon
@utkarshkumar1080
@utkarshkumar1080 Жыл бұрын
@@CheezyCode Thank you so much sir can you plz reply me on instagram ?
@aritrabhattacharya7722
@aritrabhattacharya7722 Жыл бұрын
Suppose you have a fun in viewmodel that uses flow/ livedata builder like: fun searchGif() = liveData { emit(Resource.loading("loading gifs...")) val response = gifSearchUseCase.searchGif(searchQuery) emit(response) } while testing this, is it ok to use observe forever and then collect all the livedata/flow emissions like this: val listOfTestResponses = arrayListOf() gifSearchTestViewModel.getGifSearchResult("beach").observeForever{res -> listOfTestResponses .add(res) } //-------------------------------------------------------------------------------- Truth.assertThat(listOfResponses[0].status).isEqualTo(Status.LOADING) Truth.assertThat(listOfResponses[1].status).isEqualTo(Status.SUCCESS)
@CheezyCode
@CheezyCode Жыл бұрын
nope...better to add timeout to stop observing
@aritrabhattacharya7722
@aritrabhattacharya7722 Жыл бұрын
@@CheezyCode but in this case isn't my viewmodel supposed to always emit resource.loading first and then resource.success or resource.error? So even if I mock my response, viewmodel will always emit 2 sequential data
Son ❤️ #shorts by Leisi Show
00:41
Leisi Show
Рет қаралды 7 МЛН
Llegó al techo 😱
00:37
Juan De Dios Pantoja
Рет қаралды 60 МЛН
Jumping off balcony pulls her tooth! 🫣🦷
01:00
Justin Flom
Рет қаралды 28 МЛН
哈莉奎因以为小丑不爱她了#joker #cosplay #Harriet Quinn
00:22
佐助与鸣人
Рет қаралды 7 МЛН
MVVM vs. Clean Architecture - This is the difference 💻
0:29
Philipp Lackner
Рет қаралды 28 М.
Kotlin Standard Delegates - Lazy, Observable and Vetoable
10:42
Simplified Coding
Рет қаралды 9 М.
How To Explain Test Automation Framework In Interviews For Selenium
13:42
Son ❤️ #shorts by Leisi Show
00:41
Leisi Show
Рет қаралды 7 МЛН