Тёмный

Testing Room Databases - Testing on Android - Part 6 

Philipp Lackner
Подписаться 182 тыс.
Просмотров 42 тыс.
50% 1

Опубликовано:

 

19 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 162   
@matt-g-recovers
@matt-g-recovers 3 года назад
In all seriousness, I really think this is the best Android playlist on RU-vid.
@yunusemrearslan3696
@yunusemrearslan3696 3 года назад
Not all heroes wear capes... You are a true legend dude. You saved my life thank you so much.
@rrqhoshi5140
@rrqhoshi5140 Год назад
kerennn
@hoonjung2143
@hoonjung2143 3 года назад
Hey Phil! Loving you content, especially the testing series as a lot of job offers qant some experience in TDD and I didn't (or couldn't? haha) find any comprehensive, extensive testing tutorials for Android. Thank you! I just wanted to mention that we can speed up the tests by running them as local unit tests via a simulated device (not emulated) by using Robolectric. ^^ Keep up the good stuff!
@ampo2004
@ampo2004 4 года назад
Incredible as always Philipp, I've learned a lot of things in these testing videos
@PhilippLackner
@PhilippLackner 4 года назад
Thanks man, glad you like it ✌️
@androidinsight8146
@androidinsight8146 8 месяцев назад
Excellent playlist ever seen for Testing 🎉🎉🎉🎉
@sergeytarasov5041
@sergeytarasov5041 2 года назад
One of the best explaination of room db testing. Thank U, good work.
@michaguspiel5522
@michaguspiel5522 3 года назад
Loved the video! I ran into a problems with my database and was searching for a way to test it, luckily found this video!
@jeebanbagdi3396
@jeebanbagdi3396 3 года назад
Nothing to say... just amazing. Now after seeing your videos I have fall in love with Unit Testing.
@ifeakachukwuosakwe
@ifeakachukwuosakwe 3 года назад
I just googled - how to test Android room database in Kotlin - and this channel came up ... Thank you so much for this tutorial 😊 ... You saved me
@ИванЕмелин-ш9ш
@ИванЕмелин-ш9ш 2 года назад
Good day, please tell me at 3:13 you said that we add the @RunWith(AndroidJUnit4::class) annotation to indicate to Junit that these tests are instrumented. And then at 3:50 you said that the @SmallTest annotation is needed to show that unit tests are inside. Don't these two annotations contradict each other?
@PhilippLackner
@PhilippLackner 2 года назад
No, a unit test can be instrumented or local. Unit test just means it tests a single instance (class/function) in your code. Local and instrumented just mean it either runs on the jvm or an android device
@igormorozov6311
@igormorozov6311 Год назад
I had a same question, and I am very surprising that only we two ask it ☝
@mcgaps6205
@mcgaps6205 3 года назад
12:30 LiveDataUtilAndroidTest 17:42 InstantTaskExecutorRule
@GrahamFirst
@GrahamFirst Год назад
I believe with suspend functions in your DAO, you don't need "allowMainThreadQueires", since Room will actually do the work on another thread, even if the coroutine from which you're calling it is currently executing on the main thread. Of course, you must be in a coroutine in order to call a suspend function, which is why it's recommended for Room DAO functions that don't return something observable (e.g. LiveData, as you pointed out).
@eldercampanhabaltaza
@eldercampanhabaltaza Год назад
Thanks so much for the content you are sharing. I am moving from React Native Development back to Android Development and your videos have been a great source for me to catch up with the latest technologies available. Also, as I was running the project (that I've downloaded from the GitHub link available on this video description), I faced an issue when trying to run the first test on my Mac M1. There is an incompatibility between the room version on your GitHub project and M1 Macs. This issues has been resolved on later version of room starting at 2.4.0
@GrahamFirst
@GrahamFirst Год назад
Also, in my experience, a new instance of your test class (e.g. "ShoppingDaoTest" in your example) is created to run each test case (function/method), and so I've had success just using "by lazy" to initialize things such as the DB, which is a bit simpler than "lateinit var" and an "@Before" method.
@PhilippLackner
@PhilippLackner Год назад
Lazy will keep the same reference throughout tests, while @Before creates a new one for each test. You don't want that a test case fails be aus a previous test manipulated a field lime the DB
@GrahamFirst
@GrahamFirst Год назад
@@PhilippLackner Thanks for your quick reply. I'm really curious now and would love to debug this with you if you're willing. Lazy will keep the DB around as long as the instance of the test class exists, and if the same instance of the test class were used to run more the one individual test, of course that would be bad because it would break isolation between the test cases. In pratice, however, I always find that Android Studio creates a new instance of the test class for each individual test case, even if I run them all together in one "batch". I've confirmed this by debugging. It's because of this behaviour that Lazy has worked just fine for me in practice. I'm really curious whether you see the same thing, or is it a quirk of my setup? Perhaps this behaviour isn't guaranteed, and perhaps that is the reason behind the best practice of assuming that the test class instance might be reused?
@aviksutar
@aviksutar 2 года назад
Love your course.great doing my favourite coach. keep going man..
Год назад
The simplest and most understandable video. Thank you so much. 💯💜🙏
@PhilippLackner
@PhilippLackner Год назад
Glad it was helpful!
@matt-g-recovers
@matt-g-recovers 3 года назад
Now and then you learn something so good it just makes your hair stand on end, tingles of numbly in my flesh as I feel the power flow through my fingers... but it is so simple and kinda seemingly stupid, as in no big deal...Don't judge me. CTL + to see our available functions. YES!!! hahahaha Oh the testing is good too ;)
@liveonyoutube5487
@liveonyoutube5487 3 года назад
Woow, fantastic bro. Finally I found what I am looking for 😁👏
@PhilippLackner
@PhilippLackner 3 года назад
Glad to hear that! :)
@mehdiparsaei1867
@mehdiparsaei1867 3 года назад
Thank for your amazing course.
@daniboy943
@daniboy943 2 года назад
Hi, Philipp! I understand that @SmallTest is for Unit tests, but at the same time we are testing our database (DAO is part of that, right?). In the table at 4:23 it shows Database tests should use @MediumTest, so this got me a bit confused. Could you explain why @SmallTest for DAO interface testing?
@abhimanyu.n14
@abhimanyu.n14 2 года назад
We actually are not testing the database, but the Dao code. Database is used to refer to the persistent data storage. In tests we are using "in memory database" - which stores the data only in memory. (RAM). The data is not persisted once the test completes. Integration tests can use actual database if required.
@daniboy943
@daniboy943 2 года назад
@@abhimanyu.n14 Nice, thanks for the answer!
@jeylaiskender8500
@jeylaiskender8500 3 года назад
Thank you very much! I am currently enrolled to Udacity Nanodegree and I find you videos more detailed for beginners it is very important! Subscribed :)
@markiianmykush9124
@markiianmykush9124 4 года назад
Awesome! Waiting next video!
@PhilippLackner
@PhilippLackner 4 года назад
Coming soon!
@eczema59
@eczema59 Год назад
Hello, i have problems with testing. In ShoppingDaoTest Android studio cannot resolve ShoppingItemDatabase and ShoppingDao. How can i fix this?
@AlgeriaHere
@AlgeriaHere 4 года назад
Very helpful video , thank you .
@PhilippLackner
@PhilippLackner 4 года назад
You are welcome!
@ivankvych8182
@ivankvych8182 3 года назад
Very exciting!!
@m.irtizakhursheed3040
@m.irtizakhursheed3040 3 года назад
How we can generate code coverage of instrumented test in the AndroidTest folder.
@rushidesai2836
@rushidesai2836 3 года назад
Incredible. Thanks a lot!!
@whitebl4ckk
@whitebl4ckk 3 года назад
Well done brother, awesome video, I have just one question, what about foreign keys, when one entity requiers others entities to be populated. Should I put all code in one test class
@SheikhNasratSharif
@SheikhNasratSharif 2 года назад
Awesome ❤
@Berk45632
@Berk45632 3 года назад
Tests are design to check if our code has bugs. * Philipp Testing * Philipp : "Oh. We get an error here... Let's take a look in our test case; something must be wrong here"
@PhilippLackner
@PhilippLackner 3 года назад
😂😂😂
@SpaceTimeBeing_
@SpaceTimeBeing_ 4 года назад
Can you show tests for one to many and many to many relation entities
@Aspiret620
@Aspiret620 Год назад
23:15 Lol Philipp Lackner unrated
@rajkumarsingh8664
@rajkumarsingh8664 2 года назад
Superb Dear you are amazing.
@pratikchauhan989
@pratikchauhan989 4 года назад
Thanks for so easy tutorial on testing
@PhilippLackner
@PhilippLackner 4 года назад
Most welcome 😊
@enzoteles2037
@enzoteles2037 2 года назад
very nice, you are the best of the world!!
@jorgevidal2543
@jorgevidal2543 3 года назад
Gracias hombre simplemente buen contenido de calidad..!
@VeronikaDoma-f5y
@VeronikaDoma-f5y Год назад
Thank you! 👏🙏
@JuanDanielOrnella
@JuanDanielOrnella 4 года назад
Amazing Bro!
@Berk45632
@Berk45632 3 года назад
23:14 Put a dollar in the swear jar 😂
@user-sankarsana
@user-sankarsana 3 года назад
I enjoyed it very much! Thanks. But I suppose using liveData is not very good in this case.
@safionweb
@safionweb 3 года назад
The comparison table shows that @Small tests can't access the database. Then how are we accessing it?
@דורסולומון-כ9ו
@דורסולומון-כ9ו 3 года назад
Yeah i'm wondering the same thing
@mahmoudelgamal7320
@mahmoudelgamal7320 3 года назад
very very good
@gajendrapandeya5081
@gajendrapandeya5081 4 года назад
bro just loving the series. But i have some queries. There's not even a single video in entire youtube about working with multiple table with room. Please can you create one very simple tutorial about that??
@PhilippLackner
@PhilippLackner 4 года назад
In the end you just need SQL for that and RU-vid is full of that
@ahmedaboshady9733
@ahmedaboshady9733 2 года назад
thank you very much😍
@nayeramohamed436
@nayeramohamed436 3 года назад
Can you please clarify why we didn't include a test case for observeAllShoppingItems while we did include a test case for observeTotalPrice, both of them returns live data?
@kannang2759
@kannang2759 2 года назад
Good tutorial
@swapnilkadam1391
@swapnilkadam1391 2 года назад
hey Philipp, thanks for making this. How should we handle flow?
@zunnorainshah3356
@zunnorainshah3356 11 месяцев назад
did u find a solution for flow?
@danju132
@danju132 2 года назад
Thanks
@saadbiniqbal9024
@saadbiniqbal9024 3 года назад
👏👏👏👏👏
@harishodzic3274
@harishodzic3274 Год назад
This is unit test right? Why are logic and testClasses added to and "androidTest" folder. Shouldn't unit tests be in "android" folder and UI tests in "androidTest" folder.?
@judekwashie8177
@judekwashie8177 3 года назад
Great video but I have one question. What exactly does this line \ "@get:Rule" var instantantTaskExecutorRule = InstantTaskExecutorRule()\ do?
@innocentkyalo7688
@innocentkyalo7688 3 года назад
A JUnit Test Rule that swaps the background executor used by the Architecture Components with a different one which executes each task synchronously.
@youtubecomment1150
@youtubecomment1150 3 года назад
Gold mine!
@leilasedighi1396
@leilasedighi1396 2 года назад
Hello. Thanks for this grate tutorial. Just there is one question for me: We shouldn't test every single code indivigualy? for find out easier witch part of code causing the error? Thanks in advance
@saumilpatel2480
@saumilpatel2480 4 года назад
Thank you Philip..
@PhilippLackner
@PhilippLackner 4 года назад
You're welcome :)
@mehranbehbahani3050
@mehranbehbahani3050 3 года назад
When testing the insert function, what if the query function doesn't work as expected and so the test case fails. is there a way not to depend the test case of a function (insert function) on another function that we have written ourselves (query function)? This part seemed a bit strange to me.
@animekingitachi
@animekingitachi 2 года назад
It's really helpful tutorial
@Axelfromthehudjelud
@Axelfromthehudjelud 2 года назад
I have a question, are those tests independent? We are testing our Insert function but we are calling observeAll function in the test, We are testing our Delete function, but we are calling insert and delete functions inside the test, etc. ?
@dmytromarchuk3023
@dmytromarchuk3023 3 года назад
Would you mind telling me the purpose of testing the databases? Room has been developed by Android team so they are responsible for testing it
@PhilippLackner
@PhilippLackner 3 года назад
In this simple example it probably doesn't make that much sense, but imagine you have complex sql queries and you want to test if your queries are correct and also if they still work as expected after changing them
@dmytromarchuk3023
@dmytromarchuk3023 3 года назад
@@PhilippLackner that makes much more sense. If you have custom queries - they have to be tested, because once you have to update the SQL - you can break something. Thanks!
@devetips
@devetips 3 года назад
nicely nice thank you Sir
@arash1684
@arash1684 3 года назад
Nice tutorial
@federicocreti4699
@federicocreti4699 3 года назад
Hi Philip, thanks for this course. But I have a question: what is the purpose of these tests you are writing in this specific video? I mean, what are you really testing? The functions you are testing are not even our functions, they are abstract and are implemented by Room, so what is exactly testing? The only thing I can suppose is that you are testing the query you wrote as annotations on top of dao functions, because maybe sometimes we can have complex queries, am I right? EDIT: just to be more clear, for example you are testing that insert a product insert really a product, but how is possible this cannot happens? In the end, this is done by Room, so of course it will be inserted...I hope you understand where is my doubt :D
@PhilippLackner
@PhilippLackner 3 года назад
Sure, this example here is super easy and wouldn't make sense in an actual more complex app. The point is just to show how it would work. For more complex queries and database flows it definitely makes sense to test that. It's not about testing if Room behaves right, but if you actually wrote your queries correctly.
@federicocreti4699
@federicocreti4699 3 года назад
@@PhilippLackner oh ok this is what I supposed... Ty bro ;)
@codingwithsam4992
@codingwithsam4992 2 года назад
I have a question. Why do we need to test database as it would be much simpler to open app inspection and see whats going on in the data base as we add or remote entity from mobile?
@PhilippLackner
@PhilippLackner 2 года назад
It doesn't make sense in terms of simple insertions/deletions. However if you have complex queries, you can make sure those work the way they should
@erickramones2167
@erickramones2167 2 года назад
the run annotation indicates it is an integrated test and small test annotation indicates that it is a unit test. What kind of test is it? is it both at the same time?
@pradeepkumarreddykondreddy7048
@pradeepkumarreddykondreddy7048 3 года назад
What is the difference between @RunWith(AndroidJUnit4::class) and @RunWith(AndroidJUnit4ClassRunner::class) ?
@arielapp9469
@arielapp9469 3 года назад
I'm having an error while following the tutorial in my project. the difference I have is that I have an autoGenerated primary key field in my Entity. the error I'm getting is that the database does not contain the object that I put in it. the reason is that it generates the primary key than put it in the database. is there a way to make sure the objects are the same? thank you in advance.
@chiragprajapati3989
@chiragprajapati3989 4 года назад
nice explanation
@PhilippLackner
@PhilippLackner 4 года назад
Thanks and welcome
@juancarlosnino379
@juancarlosnino379 3 года назад
thx a lot!
@ZaidZakir
@ZaidZakir 3 года назад
you the best man!!!!!!!!!!!!!!
@ritamdey6262
@ritamdey6262 4 года назад
Hey! Is turning on Main Thread Query execution really necessary?
@PhilippLackner
@PhilippLackner 4 года назад
Well, we want to execute everything in the main thread, so yes
@atulbirthwal3931
@atulbirthwal3931 2 года назад
Hey Philipp, I am just curious about that LiveData works asynchronously? can you please explain
@haissayf
@haissayf 4 года назад
Thank you.
@PhilippLackner
@PhilippLackner 4 года назад
You're welcome!
@akshaychande9698
@akshaychande9698 3 года назад
How to see code coverage for written test cases?n how to exclude file or packges from that coverage
@marlonlom
@marlonlom 3 года назад
if the room database usage is in an android library, which setup can i follow for perform the testing?
@antoniokomangyudistira4150
@antoniokomangyudistira4150 4 года назад
Thank you sir
@PhilippLackner
@PhilippLackner 4 года назад
Welcome
@SerhiiOr
@SerhiiOr 4 года назад
Bro, why we use @SmallTest in androidTest?Shouldn't we use @MediumTest? Or it doesn't matter where to use, only has sence what we have inside test?
@PhilippLackner
@PhilippLackner 4 года назад
Small test means Unit test. And unit test means we only test one class. And here we only test our Dao, so all of these are unit tests
@SerhiiOr
@SerhiiOr 4 года назад
@@PhilippLackner and theoretically we can do all this stuff in test directory?
@PhilippLackner
@PhilippLackner 4 года назад
@@SerhiiOr yes, but then you need sqlite installed on your pc. You shouldn't do that as I said because then you're using another sqlite version than on your android device
@SerhiiOr
@SerhiiOr 4 года назад
@@PhilippLackner thanks!
@puszkinowski
@puszkinowski 3 года назад
great vid. What exactly does 'get' before Rule annotation do ? Ok, i supposes its getting the rule :) but why is has to be there and not in others annotations?
@akashdeepwadhwa5828
@akashdeepwadhwa5828 3 года назад
i think to declare that instead of executing functions that performs asynchroniously ..use that rule object(to store the details of tasks who are running asynchroniously )to specify that functions should run in sequence because we are testing it in mainthread ..like write/update data then other methods like read and all that
@puszkinowski
@puszkinowski 3 года назад
@@akashdeepwadhwa5828 Thank you :)
@mehulbisht9708
@mehulbisht9708 4 года назад
16:51 how much is the RAM on your System ? my laptop has 4 GB and i don't think it will work for me since running an android emulator slows it down a lot. Can a physical device also work for these test cases ? ( My laptop does have Intel I5 - 10th gen with 1 TB HDD and 256 GB of SSD, still i think the 4 GB ram is costing me the emulator, your opinion on this please? )
@PhilippLackner
@PhilippLackner 4 года назад
I have 16gb of ram and you can use a physical device as well
@mehulbisht9708
@mehulbisht9708 4 года назад
@@PhilippLackner cool
@studyonline3236
@studyonline3236 10 месяцев назад
This is an android-testing bible.
@marlonlom
@marlonlom 3 года назад
which dependencies are needed for room database testing?
@frankleth9380
@frankleth9380 4 года назад
You are the best. I'm always waiting for your videos
@PhilippLackner
@PhilippLackner 4 года назад
Thanks 👌
@pejmanazad5852
@pejmanazad5852 3 года назад
one question happen, why we need test room functionality like(CRUD)?
@PhilippLackner
@PhilippLackner 3 года назад
In this simple case for demonstration it doesn't make much sense, but if you have complex queries, it makes sense to test if these are working as expected
@dennisthegamer2376
@dennisthegamer2376 Год назад
Thanks for the example. But wouldn't testing a repository make more sense? Testing a DAO doesn't really seem necessary to me, it mainly tests room, and maybe your skill to write basic SQL queries xD.
@thearpansircar
@thearpansircar 4 года назад
Lmao, I saw this channel name and was about to inform you that someone was using your videos. Then I remembered how you made an entire video about changing your channel name.
@PhilippLackner
@PhilippLackner 4 года назад
Lol :D
@vishnusimha8264
@vishnusimha8264 3 года назад
Hi @philip Lackner I don't see any code in the git hub can you or someone please share the source code?
@codingWithAj
@codingWithAj Год назад
runBlockingTest{ } is now deprecated in favour of runTest{ }
@mado6066
@mado6066 2 года назад
Hi, Philipp how i test dao with Bitmab parameter?
@AwesomeDevNotes
@AwesomeDevNotes 4 года назад
𓌤 𓌥 𓌦 𓌧 𓌨
@JamesBond-mq7pd
@JamesBond-mq7pd 3 года назад
10:08 tried to press Control + Space but nothing happened.
@hosseinamini2443
@hosseinamini2443 3 года назад
In a real project, is it a good idea to write tests for third-party libraries? Because most of these libraries are tested by their creators
@PhilippLackner
@PhilippLackner 3 года назад
No, but writing tests how your code interacts with them
@aceoftheplays4664
@aceoftheplays4664 3 года назад
Hi, does anyone have the LiveDataUtil class but in java ? I am kind of struggling with converting it. Yes I do java it is a requirement dont bite my head off for it :D
@JamesBond-mq7pd
@JamesBond-mq7pd 3 года назад
13:20 can you provide original link of that code?
@rautermann
@rautermann 3 года назад
The part with runBlockingTest seems to be Kotlin specific - how would I do that with Java?
@PhilippLackner
@PhilippLackner 3 года назад
With Java, you couldn't use coroutines at all. You would probably use threads or so. There is no reason not to use kotlin for Android nowadays
@rautermann
@rautermann 3 года назад
@@PhilippLackner I see, thanks! And thank you for the great content! (The reason to use Java is that I'm a beginner and have already tried to learn way too many languages this year... and btw, I think your pronunciation of kuh-routine is hilarious xD)
@PhilippLackner
@PhilippLackner 3 года назад
@@rautermann german spotted :D
@rautermann
@rautermann 3 года назад
@@PhilippLackner Liebe Grüße aus Wien ;P
@PhilippLackner
@PhilippLackner 3 года назад
@@rautermann Grüße aus Hannover zurück 💪
@nicoqueijo
@nicoqueijo 3 года назад
How come you are not using JUnit 5?
@prkofc
@prkofc 3 года назад
I am getting this "Test running failed: Process crashed."
@chi94
@chi94 Год назад
this got complicated real quickly lol
@s.j.6096
@s.j.6096 2 года назад
Why you don't write in the title if your work with kotlin or Java?
@PhilippLackner
@PhilippLackner 2 года назад
To trigger Java developers
@s.j.6096
@s.j.6096 2 года назад
@@PhilippLackner OK, I see.
@travelogue.austria
@travelogue.austria 2 года назад
Thank you so much for this wonderful tutorial I have a problem with this episode I wrote the code and got this Error: java.lang.RuntimeException: cannot find implementation for com.application.unittest.data.local.ShoppingItemDatabase. ShoppingItemDatabase_Impl does not exist at androidx.room.Room.getGeneratedImplementation(Room.java:100) at androidx.room.RoomDatabase$Builder.build(RoomDatabase.java:1486) at com.application.unittest.data.local.ShoppingDaoTest.setup(ShoppingDaoTest.kt:38) I checked stackoverflow but those solutions didn't work for, so what should I do?
@amineayachi335
@amineayachi335 2 года назад
thanks
Далее
БЕЛКА РОЖАЕТ? #cat
00:29
Просмотров 297 тыс.
WHO IS MORE GREEDY?!
00:18
Просмотров 1,1 млн
Full Guide to Jetpack Compose Effect Handlers
24:56
Просмотров 93 тыс.
SQLite Database for Android - Full Course
1:28:22
Просмотров 250 тыс.
Make Your Code Clean With the SOLID Principles
18:24
Просмотров 99 тыс.
ТЕСТИРОВАНИЕ НА JAVA (JUNIT, MOCKITO)
9:14