Hey, Nelson, you could record a tutorial teaching How to configure this AbstractTestcontainers and all that stuff to replace H2 DB. That's really useful, your videos are amazing
Whatever you are talking about, maybe true for complex projects or high data loads. But 90% of projects have very simple crud operations. Anyhow, it's not always about unit testing. Before going to production, usually, code is tested by QA, performance, load testing, security team and UAT. with h2 database writing test cases is easy.
I still think H2 in testing is fine, if you ain't performing limited / any database-specific functions. Spinning up docker to run something simple during integration test, hmm it seems overkill
Hello, Thank you for the video. I have 7+ years production expedience and want to add few moments which i learned). So better a bad test than no test). Yes h2 is not totally equal to production ready databases and what works on h2 might not work on MySql,Postgres... But it is
I have also encountered situations where the testing results of H2 Database and PostgreSQL are different. This video has further convinced me that H2 should not be used. Thank you for sharing.
While H2 is not recommended sometimes using it is the only way to have your tests. For example, the most recent client of ours provided us with their CITRIX vms, so this rendered both docker and testcontainers impossible to use. What I want to say is that we need H2 in order to cover ignorance of our clients. So again, when we have "theory" VS "real world" problem. Thanks for this video!
I am studying his course from two years ago on JUnit testing and he recommends using H2, in fact he is teaching it, at that moment the thumbnail of this video came to mind, now I don't know if I should learn like this or not...?
Love the way you teach! I just finished my first h2 todo project. But I am from PHP and MySQL so I needed some instruction on host to get a MySQL database with the JAVA project instead of H2. This was a little over my head. I am off to your website to see if you have a course that might fit my level a little better. TY!
Yes please make a video on testing (for controller, repository and service layer). I don't understand how to test😢 I can write code but i cannot write tests for it😑
We need more videos about testing and about Test Containers and Integration Testing. Please can you in the future make tutorials about Spring Boot Reactive?
Hi, Just a quick comment... In general in Java world, you should use JPA and Hibernate (or similar) to handle DB. So, as far as you're using this abstraction, there is no big deal to use H2. And by the way, the use of custom DB functions is discouraged. Better to stay with "standard SQL" (or similar from Hibernate). So it means it's perfectly safe to use H2 to make some kind of unit tests, for instance those that ensure the correct lazy loading or the persistence effectiveness, your real (basic)persistence logic, etc... And it's not replacing integration tests with whatever DB you want... An advantage to H2, is the possibility to launch directly some SQL script in the connection String. That way, you can initialize a database correctly (with specific SQL like the one that was created by the DBA). True story, if I was not trying to use H2 on one of the project I collaborated, then I never been able to detect fundamental PROD DB problem. It was precisely because I forced myself to standardize things through JPA and Hibernate, and validated both local H2 and other environment Oracle that I found some previous migration was not completed correctly... I'll not advocate to use H2, I'll just wanted to say it's another great tool that can be used. It's a little unfair to say it's not safe, if you pay attention to the limitations...
Correct me if I'm wrong, but in case if I cannot avoid using a feature provided by a custom DB function, I'd use it, rather than inventing a wheel by implementing it myself and putting a responsibility of supporting this logic on my team
@@maksym.pavlenko, I'll say that you can maybe challenge the real necessity to have the custom DB function. And well, if it's really not possible to do without this custom function, then there is no reason to not use it. It's just that you can "skip" the particular part that use the custom function by skipping the H2 test, and try to have unit tests / integration tests with H2 for everything else. Then it's a matter of isolation, more than avoiding custom DB functions.
@@gaetanbayenay8730 all this comes from unreliability of such functions or the fact the migration to another DB without unsupported functions could be easier?
@@maksym.pavlenko I think it's more complex than that. If the goal is to have the ability to change DB, then the standardization is a must. So, higher expectation means to think about the problem (and the way the data are stored) differently. It's not only the pure data, or the way to handle them, but also the meaning of the data organization. That's the reason why it's important to challenge the real need for custom function. Another point is how to deal in code with the data. If a custom function can be avoided by using similar data manipulation within Java (for instance with java streams), or by rethinking the separation of concerns with a split into microservices, then it's also a valid answer to the problem. And maybe it's the DB technology itself that can be changed (by using non relational DB, or something totally different). So, there is room to avoid custom functions, depending on the needs and the liberty in adressing the problem... :) ... But at the end, if the functions exists, there is a need too, and good reasons to use them, with the knowledge that the code is no more standardized.
I mean, this is why we use abstraction. DBs might have differences, but we should develop app as flexible as possible. So using H2 is good if it’s justified. If we use some specific function from PostgreSQL in out test, maybe we should consider changing it
Ran into this at work recently. H2 dialect for Oracle isn’t complete and it was literally impossible to test my DAO and had to mock it… which is useless!
Thank for granting my wish, amigo! I know this video is just not for me but I am also one of the people who requested it. Even in your big time of fasting 🥰
really great Nelson! Thank you so much for sharing. I've been following you since the beginning and I can say your content helped me a lot on my career, I'm an amigoscode fan definitely haha. I really want to buy the Full Stack Professional course but right now my budget is a little tight, would be awesome to get a magic coupon code. Thank you so much for everything, you're an inspiration to me!
It sounds fine, but it works on the Development environment (local), but this cannot be easily done over automated CI/CD, e.g. Jenkins or GitHub Actions, it is possible but requires extra resources and configuration and create a dependency on the database (must be running before the test), UTs are supposed to be isolated. that's why mock libraries were created, I understand your point I've created UTs that run against a "real" database, but I've disabled them when running the automated CI/CD because I cannot modify the "DevOps infrastructure" just to run containers.
Hey Nelson! Where can I find your code formatter setup? Also I’m staying with dillema which MacBook Pro is best For fullstack oriented programming with a budget of 2k$ (prefer 14’ ones) It will be better to buy M2 Pro or M1 Pro with upgraded RAM? Or maybe other one with Intel processor?
This may trigger someone but I say it in good faith. Consider setting a poll on whether or not you should continue with these new thumbnails where you look shocked/confused etc vs the legendary thumbs up.
THANKS Nilson, always wonderful video ! . I'd love to make a video on how to use docker to replace H2 cos right now I'm learning it, and still I'm not quite sure to understand how to use it in a concrete project like this your project.
Hey Nelson! Good video. I would like to see a TestContainer tutorial on using it, and I have a quick question. If I'm using an interface that implements JPARepository without using custom queries, should I need to write unit test for the original operations? Should I test the interface? Or should I create a class that implements my custom interface and then create a unit test for this new class? I really appreciate this video Nelson!!
Isn't necessary to test this JPA interfaces, You'll need to test it just in case of having custom queries. All "default" queries are tested over years by spring community :)
The H2 technology is used by many book authors to explain concepts. I have never liked this foolish approach, and I am happy to see someone who thinks like me for the first time.
Hi! What do you think about using SQLite as an alternative to H2? I know it has similar limitations but if the application is small or simple it may works well, right?
I am a principal software engineer. I like a lot of your videos and give you props for explaining best practices to junior engineers in a clear and concise way. However, this video is an exception. Judging by the comments, nobody really understood your point. And I must say, your point is lost because for some reason you are talking about H2 and “in memory-database” like that’s something special. The only sensible thing you can say is that a test environment should as closely as possible mimic the production environment. Now that’s a true statement. What does H2 in particular have to do with the price of tea in china? Same would be true if you said “Don’t use Oracle to test MySQL queries”. Now, I get it, you are trying to say, that the ease of getting an H2 running makes it super easy to use for testing. But that’s largely irrelevant, for the point you are trying to make.
Why? h2 is excellent to teach the basic of SQL without messing with a db install. H2 is not designed for a production serious enviroment. Learn the basic of ORM, SQL, JDBC and then kick off the H2 if you want.
I have been trying for weeks to create the simplest application: something that creates users and saves it into an H2 database. But for some godforsaken reason, all POST requests made to the register endpoint return a status 200 instead of a 201, so nothing is ever created on the database. Why? I have asked everyone, from teachers and professionals, to chat GPT and no one seems to find the answer. I'm beginning to think the issue may be related somehow to the H2 database. I see no other explanation.
Dear Nelson If you are opposing of using H-2 in first place then why haven't you updated your course "software testing" (listed on your website) which uses H-2 db. On top of that throughout the course you are mocking repository layer and injecting mock on service layer. If this is not the best practice to follow then why you haven't you updated this course with docker implementation. H-2 is quite good with basic CRUD operations but docker is one of the safe and reliable option for testing. Please record a video for unit as well integration testing with docker test containers. At least this would help me learn all the major concepts of software testing. But I am still not clear if mocking service layer or repository layer is OK for isolation testing or even unit as well as integration testing! what type of testing practices an enterprise company follows ?
I agree that nowdays it is a best practice to use testcontainers to have best compatibility across all environments. But for those who stuck with H2 for any reason, keep in mind that you have some flexibility by creating aliases for Java based functions, ie: CREATE ALIAS IF NOT EXISTS TRUNC FOR "my.package.MyH2Functions.trunc";
Hey, Nelson, you could record a tutorial teaching How to configure this AbstractTestcontainers and all that stuff to replace H2 DB. That's really useful, your videos are amazing
I would like to watch that video)
Will do
Good idea!!!
@@amigoscode thanks man
Whatever you are talking about, maybe true for complex projects or high data loads. But 90% of projects have very simple crud operations. Anyhow, it's not always about unit testing. Before going to production, usually, code is tested by QA, performance, load testing, security team and UAT. with h2 database writing test cases is easy.
I still think H2 in testing is fine, if you ain't performing limited / any database-specific functions. Spinning up docker to run something simple during integration test, hmm it seems overkill
Hello, Thank you for the video. I have 7+ years production expedience and want to add few moments which i learned). So better a bad test than no test). Yes h2 is not totally equal to production ready databases and what works on h2 might not work on MySql,Postgres... But it is
I have also encountered situations where the testing results of H2 Database and PostgreSQL are different.
This video has further convinced me that H2 should not be used.
Thank you for sharing.
Loved the video Nelson please do a tutorial on TestContainers and setting it up a little in depth ❤ Thank you!
While H2 is not recommended sometimes using it is the only way to have your tests. For example, the most recent client of ours provided us with their CITRIX vms, so this rendered both docker and testcontainers impossible to use. What I want to say is that we need H2 in order to cover ignorance of our clients. So again, when we have "theory" VS "real world" problem. Thanks for this video!
I am studying his course from two years ago on JUnit testing and he recommends using H2, in fact he is teaching it, at that moment the thumbnail of this video came to mind, now I don't know if I should learn like this or not...?
Love the way you teach! I just finished my first h2 todo project. But I am from PHP and MySQL so I needed some instruction on host to get a MySQL database with the JAVA project instead of H2. This was a little over my head. I am off to your website to see if you have a course that might fit my level a little better. TY!
Yes please make a video on testing (for controller, repository and service layer).
I don't understand how to test😢
I can write code but i cannot write tests for it😑
We need more videos about testing and about Test Containers and Integration Testing.
Please can you in the future make tutorials about Spring Boot Reactive?
Hi,
Just a quick comment... In general in Java world, you should use JPA and Hibernate (or similar) to handle DB. So, as far as you're using this abstraction, there is no big deal to use H2. And by the way, the use of custom DB functions is discouraged. Better to stay with "standard SQL" (or similar from Hibernate).
So it means it's perfectly safe to use H2 to make some kind of unit tests, for instance those that ensure the correct lazy loading or the persistence effectiveness, your real (basic)persistence logic, etc... And it's not replacing integration tests with whatever DB you want...
An advantage to H2, is the possibility to launch directly some SQL script in the connection String. That way, you can initialize a database correctly (with specific SQL like the one that was created by the DBA).
True story, if I was not trying to use H2 on one of the project I collaborated, then I never been able to detect fundamental PROD DB problem. It was precisely because I forced myself to standardize things through JPA and Hibernate, and validated both local H2 and other environment Oracle that I found some previous migration was not completed correctly...
I'll not advocate to use H2, I'll just wanted to say it's another great tool that can be used. It's a little unfair to say it's not safe, if you pay attention to the limitations...
Correct me if I'm wrong, but in case if I cannot avoid using a feature provided by a custom DB function, I'd use it, rather than inventing a wheel by implementing it myself and putting a responsibility of supporting this logic on my team
@@maksym.pavlenko, I'll say that you can maybe challenge the real necessity to have the custom DB function. And well, if it's really not possible to do without this custom function, then there is no reason to not use it. It's just that you can "skip" the particular part that use the custom function by skipping the H2 test, and try to have unit tests / integration tests with H2 for everything else. Then it's a matter of isolation, more than avoiding custom DB functions.
@@gaetanbayenay8730 all this comes from unreliability of such functions or the fact the migration to another DB without unsupported functions could be easier?
@@maksym.pavlenko I think it's more complex than that. If the goal is to have the ability to change DB, then the standardization is a must. So, higher expectation means to think about the problem (and the way the data are stored) differently. It's not only the pure data, or the way to handle them, but also the meaning of the data organization. That's the reason why it's important to challenge the real need for custom function.
Another point is how to deal in code with the data. If a custom function can be avoided by using similar data manipulation within Java (for instance with java streams), or by rethinking the separation of concerns with a split into microservices, then it's also a valid answer to the problem.
And maybe it's the DB technology itself that can be changed (by using non relational DB, or something totally different).
So, there is room to avoid custom functions, depending on the needs and the liberty in adressing the problem... :) ... But at the end, if the functions exists, there is a need too, and good reasons to use them, with the knowledge that the code is no more standardized.
I mean, this is why we use abstraction. DBs might have differences, but we should develop app as flexible as possible. So using H2 is good if it’s justified. If we use some specific function from PostgreSQL in out test, maybe we should consider changing it
solid point
Perfecto Amigo, we need the tutorials on test containers and all the testing stuff in spring boot soon. Love you ❤
Ran into this at work recently. H2 dialect for Oracle isn’t complete and it was literally impossible to test my DAO and had to mock it… which is useless!
Thank for granting my wish, amigo! I know this video is just not for me but I am also one of the people who requested it. Even in your big time of fasting 🥰
really great Nelson! Thank you so much for sharing. I've been following you since the beginning and I can say your content helped me a lot on my career, I'm an amigoscode fan definitely haha. I really want to buy the Full Stack Professional course but right now my budget is a little tight, would be awesome to get a magic coupon code. Thank you so much for everything, you're an inspiration to me!
It sounds fine, but it works on the Development environment (local), but this cannot be easily done over automated CI/CD, e.g. Jenkins or GitHub Actions, it is possible but requires extra resources and configuration and create a dependency on the database (must be running before the test), UTs are supposed to be isolated. that's why mock libraries were created, I understand your point I've created UTs that run against a "real" database, but I've disabled them when running the automated CI/CD because I cannot modify the "DevOps infrastructure" just to run containers.
yes, we want to see how to use testcontainers from scratch, plz
Hey amigo i just wanted to let you know I got into software development recently and you have been a great help keep up the good work man❤
Thank you. Would love to see the TestContainers video
H2 is absolutely fine for QUCK testing, without going to the effort of a "near to production as possible" environment
Hi Yes we need this video about containers.
Hey Nelson!
Where can I find your code formatter setup?
Also I’m staying with dillema which MacBook Pro is best For fullstack oriented programming with a budget of 2k$ (prefer 14’ ones)
It will be better to buy M2 Pro or M1 Pro with upgraded RAM? Or maybe other one with Intel processor?
Great video. Please show us how to do test containers :)
This may trigger someone but I say it in good faith. Consider setting a poll on whether or not you should continue with these new thumbnails where you look shocked/confused etc vs the legendary thumbs up.
Thanks for this, this approach is good for developer using docker.
Hello, Nelson! Is it possible to launch testcontainers automatically before tests start? And stop it after?
THANKS Nilson, always wonderful video ! . I'd love to make a video on how to use docker to replace H2 cos right now I'm learning it, and still I'm not quite sure to understand how to use it in a concrete project like this your project.
I would also like to watch a video about testcontainers, especially with spring boot 3.1
yes, please make some example how to setup TestContainers, how to use it :) will be helpful for sure.
we're all waiting for the testing containers tutorial sir
thanks for the good content!
You should update your JUnit course from 2 years ago where you literally recommend using H2 , or add some notification in that video.
It would be REALLY good to have the video on test containers
what about external service ? should we mock or any other approach
Hey Nelson! Good video. I would like to see a TestContainer tutorial on using it, and I have a quick question. If I'm using an interface that implements JPARepository without using custom queries, should I need to write unit test for the original operations? Should I test the interface? Or should I create a class that implements my custom interface and then create a unit test for this new class? I really appreciate this video Nelson!!
Isn't necessary to test this JPA interfaces, You'll need to test it just in case of having custom queries. All "default" queries are tested over years by spring community :)
Should I mock repository in service layer? If I tested custom queries of repository using testcontainers?
Hello Nelson, thanks as usual. Can you make a video on TestContainers and your configuration? Thanks mate
For the container db test, it quite take time when run.
Hi, I would love to see a video on setting up TestContainers
Please Nelson! A video for testcontainers, including with kafka reactive! hands 🙏🏾
AbstractTestcontainers would be really great to see! Hope you can prepare such material soon 😀
The H2 technology is used by many book authors to explain concepts. I have never liked this foolish approach, and I am happy to see someone who thinks like me for the first time.
is that means H2 has no use cases? can you explain why did you call it foolish approach?
Hi! What do you think about using SQLite as an alternative to H2? I know it has similar limitations but if the application is small or simple it may works well, right?
I guess mongoDb would be good option with mongo atlas, but it's nosql
Yes! Please! I'm interested in Testcontainers :)
Great video! I would like if you could put a video from scratch about test containers.
I am a principal software engineer. I like a lot of your videos and give you props for explaining best practices to junior engineers in a clear and concise way. However, this video is an exception.
Judging by the comments, nobody really understood your point. And I must say, your point is lost because for some reason you are talking about H2 and “in memory-database” like that’s something special.
The only sensible thing you can say is that a test environment should as closely as possible mimic the production environment. Now that’s a true statement. What does H2 in particular have to do with the price of tea in china?
Same would be true if you said “Don’t use Oracle to test MySQL queries”. Now, I get it, you are trying to say, that the ease of getting an H2 running makes it super easy to use for testing. But that’s largely irrelevant, for the point you are trying to make.
Great content, keep going bro!
Hey Nelson! can you make tutorial on SpringAOP, couldn't really find any perfect explanation
Hi i had one doubt can't we use mockito instead of actual database call?
Why? h2 is excellent to teach the basic of SQL without messing with a db install. H2 is not designed for a production serious enviroment. Learn the basic of ORM, SQL, JDBC and then kick off the H2 if you want.
I have been trying for weeks to create the simplest application: something that creates users and saves it into an H2 database.
But for some godforsaken reason, all POST requests made to the register endpoint return a status 200 instead of a 201, so nothing is ever created on the database.
Why? I have asked everyone, from teachers and professionals, to chat GPT and no one seems to find the answer.
I'm beginning to think the issue may be related somehow to the H2 database. I see no other explanation.
@@TheUrizen ... its a conspiracy ...
please do a deep dive tutorial into testcontainers
Dear Nelson
If you are opposing of using H-2 in first place then why haven't you updated your course "software testing" (listed on your website) which uses H-2 db. On top of that throughout the course you are mocking repository layer and injecting mock on service layer. If this is not the best practice to follow then why you haven't you updated this course with docker implementation. H-2 is quite good with basic CRUD operations but docker is one of the safe and reliable option for testing.
Please record a video for unit as well integration testing with docker test containers. At least this would help me learn all the major concepts of software testing.
But I am still not clear if mocking service layer or repository layer is OK for isolation testing or even unit as well as integration testing!
what type of testing practices an enterprise company follows ?
Easy solution. Just use H2 in production😎
That’s cool but when I try it on my PC, with an Oracle test container, it takes 2 minutes to run a single test
how you have automated the firework at the end of the tests?
"How to configure this AbstractTestcontainers and all that stuff to replace H2 DB?"
Just do it, please😎👊
Awesome Nelson, testcontainers vid pleeeese!😊
Thank you for the great video!
we want to see testcontainers!
But how would I setup the docker in a CI environment?
Need TestContainers video 🔥🔥🔥🔥
Testcontainers deeply from scratch please!
Thanks for your videos
Docker is a life saver
The video was great, but why you have to add that rainbow??
This is not ideal for tests though as with tests I run them on an environment that doesn't have a database instead just uses the memory database
What about SQLite ?
Assalamu alaykum and Thank you very much
I'm developing a small application that uses an H2 DB and got real spooked 😳.
Could you please publish source code?
Ok. I promise that. Can you hire me?
Please do record a video on setting up TestContainers! That's soooo useful!!
Show how tô do this
Hey man. I appreciate your content, but the thumbnails are kind of off putting. 😬
hey amigoo
First🎉🎉🎉
Second🎉
You can have his course for free. Dont buy his overpriced course
If you get a lot of value from his content why not show some support ?
I agree that nowdays it is a best practice to use testcontainers to have best compatibility across all environments. But for those who stuck with H2 for any reason, keep in mind that you have some flexibility by creating aliases for Java based functions, ie: CREATE ALIAS IF NOT EXISTS TRUNC FOR "my.package.MyH2Functions.trunc";