Пікірлер
@24035709
@24035709 15 күн бұрын
background music is distracting
@sefumies
@sefumies 28 күн бұрын
I wasn't aware that @DataJpaTest auto configures the @JdbcTemplate, is this correct, as I cannot find any documentation on this
@priyankawagh5217
@priyankawagh5217 Ай бұрын
Since long time I was desperate to understand details about how to clearly test each and everything about spring boot app/microservies and avoid repeatative declaration of similar data yet keeping it seperate if required. This video answered all the questions that I had! thanks alot!
@codewitharho
@codewitharho Ай бұрын
I’m very pleased that it was helpful!
@priyankawagh5217
@priyankawagh5217 Ай бұрын
Thanks!!!
@codewitharho
@codewitharho Ай бұрын
You’re welcome!
@adityanehra
@adityanehra 3 ай бұрын
good job Bro.
@codewitharho
@codewitharho 3 ай бұрын
Thank you!
@tko1176
@tko1176 4 ай бұрын
When you remove the flush part, when does the flush occurs to make fail the test again? 14:36
@codewitharho
@codewitharho 4 ай бұрын
It fails because it doesn't flush. Without specifically flushing it's up to the framework to do the flushing and we have no control of when that happens. The constraint check only happens on the database level after the flush.
@tko1176
@tko1176 4 ай бұрын
@@codewitharho I understand. Thank you.
@nishiths9228
@nishiths9228 5 ай бұрын
Splendid. So much learning and quality learnings. Thank you so much for educating on writing better tests.
@codewitharho
@codewitharho 5 ай бұрын
Always nice to hear it's helpful content!
@elkinlimasrojas1294
@elkinlimasrojas1294 7 ай бұрын
Good morning. first thank for sharing. my question is when I use server.servlet.context-path=/api/v1/ my test with @WebMvcTest don't know this path. why? when write yhe path in the controller the test was happy
@codewitharho
@codewitharho 6 ай бұрын
Probably because @WebMvcTest is a slice that only loads part of the application context. You could test your endpoints without the context path with @WebMvcTest. Then just have a single @SpringBootTest that validates the context path.
@alanhabib1942
@alanhabib1942 7 ай бұрын
This was good. Are there any in depth Spring Boot Test classes?
@codewitharho
@codewitharho 6 ай бұрын
Unfortunately not (yet). I have been struggling to find time to make more in-depth videos.
@alanhabib1942
@alanhabib1942 6 ай бұрын
If you ever made one that would be awesome!@@codewitharho
@ОлегПаламарчук-р5к
@ОлегПаламарчук-р5к 7 ай бұрын
Thanks, it is really true. Many developers don't know the difference between Unit and Integration test. It is sad.
@codewitharho
@codewitharho 6 ай бұрын
Unfortunate but we can try to share information!
@Sedri14
@Sedri14 8 ай бұрын
Brilliant explanation, exactly what I was looking for. Thanks!
@codewitharho
@codewitharho 8 ай бұрын
Happy to hear that!
@reallylordofnothing
@reallylordofnothing 8 ай бұрын
can someone explain what does this unit test actually achieve? How is it useful? On what condition will this test fail in order for me to know that writing this test was useful?
@codewitharho
@codewitharho 8 ай бұрын
Examples can sometimes be too simple, right? The takeaway here is to not mix framework details in your business logic tests.
@illia4503
@illia4503 10 ай бұрын
Thanks! Very useful video!
@codewitharho
@codewitharho 8 ай бұрын
Glad you liked it!
@PapaFranciscoOk
@PapaFranciscoOk 11 ай бұрын
Arho, just finished this testing mini-series and let me tell you that this is by far the best spring boot testing guide i've seen so far. Not only you covered all the important topics but you also did that in very concise videos. You won a new sub and im looking forward to read all your articles and see new videos from you. Thanks and greetings from Argentina!
@codewitharho
@codewitharho 11 ай бұрын
Thanks a lot for the kind words! It is always warming my heart when someone finds the content useful.
@Дмитрий-з7м9е
@Дмитрий-з7м9е Жыл бұрын
Thank you sir!
@codewitharho
@codewitharho Жыл бұрын
You’re welcome!
@srinivaschaitanya3305
@srinivaschaitanya3305 Жыл бұрын
While most of videos explain how to write tests, you are explaining WHY unit tests are not enough and why we should use other kinds of tests..this makes absolute sense..thanks so much
@codewitharho
@codewitharho Жыл бұрын
I’m glad it has been useful!
@MrTutiplengo
@MrTutiplengo Жыл бұрын
I'm not sure I understand the point of these kinds of tests. We are basically mocking everything and providing a perfectly predictable path. In the end, the only thing being actually tested is the methods return value. And if we look at the method's signature, we already know what it's going to be.
@codewitharho
@codewitharho Жыл бұрын
The point here is the ability to write unit tests without the Spring framework. When choosing examples you have to always choose between simplism and realism.
@MrTutiplengo
@MrTutiplengo Жыл бұрын
Why do we need to test for field validation and endpoint mapping? These are part of the spring framework and fall outside of the scope of our code. Shouldn't testing focus on testing the application's business logic?
@codewitharho
@codewitharho Жыл бұрын
The goal is to test that validation takes place and endpoints respond, not the actual Spring implementation of such concerns. For that to happen, it’s still our job to add correct annotations and configurations. Testing the business logic is important, yes. But your business logic doesn’t care what technology is driving it. Unless you have a CRUD app you probably shouldn’t test your business logic through the controllers. Here’s an article that goes much deeper in the architectural side of things: www.arhohuttunen.com/hexagonal-architecture-spring-boot/
@robinmathur5807
@robinmathur5807 Жыл бұрын
Thanks for making good content for us, I would appreciate if you make some content on internal of JUnit Framework and how different annotations on class level like @JsonTest/@MockitoExtension works with JUnit framework.
@codewitharho
@codewitharho Жыл бұрын
Looks like I have forgotten to reply, but that sounds like a good idea for better understanding.
@wirstan
@wirstan Жыл бұрын
RecordedRequest request = mockwebserver.takeRequest(); takes a long time and hangs, why ?
@codewitharho
@codewitharho Жыл бұрын
Sounds like maybe it’s not making the request at all. I’d first make sure that it actually does make the request before looking further.
@wirstan
@wirstan Жыл бұрын
@@codewitharho i found the solution, baseurl was incorrect 😊
@babuperumal7664
@babuperumal7664 Жыл бұрын
Hi i used this, test case is getting passed. but it is not covering in sonarcube code coverage. is this will cover in code coverage?
@codewitharho
@codewitharho Жыл бұрын
Have you configured JaCoCo correctly? Just running the tests alone is not enough, the coverage must be measured with JaCoCo or a similar coverage tool.
@h.k3260
@h.k3260 Жыл бұрын
Anybody have any experience using Junit 5 for composable functions
@codewitharho
@codewitharho Жыл бұрын
Can you be a little more specific?
@ramsay9912
@ramsay9912 Жыл бұрын
Amazing! 👏 you teach good stuff, thank you Arho
@codewitharho
@codewitharho Жыл бұрын
Thank you!
@gallanonim4914
@gallanonim4914 Жыл бұрын
Arho - you provide wonderful content, great job 💪 Is there any chance to see new videos from you?
@codewitharho
@codewitharho Жыл бұрын
Thank you! I should eventually get back to it - currently in the middle of moving places and renovations.
@codingwithraphael
@codingwithraphael Жыл бұрын
it would be awesome if you also create videos using webflux =)
@ezra.rajkumar
@ezra.rajkumar Жыл бұрын
Thanks for sharing. This really helps me to write better tests
@codewitharho
@codewitharho Жыл бұрын
Cool!
@icstreispe13
@icstreispe13 Жыл бұрын
Great work. How about making a video for writing tests for SpringBatch?
@codewitharho
@codewitharho Жыл бұрын
I haven’t been using Spring Batch much but I won’t rule out the possibility!
@gallanonim4914
@gallanonim4914 Жыл бұрын
@codewitharho Are you planning a WireMock series? I'm very impressed with your approach to the subject of tests. I will definitely recommend this channel further, it's a real gem. Thank you for your amazing work.
@gallanonim4914
@gallanonim4914 Жыл бұрын
Great, top content. Greetings from Poland!
@codewitharho
@codewitharho Жыл бұрын
Thank you!
@manzii111
@manzii111 Жыл бұрын
Absolutely top quality series about testing Spring Boot, thanks for sharing this knowledge.
@codewitharho
@codewitharho Жыл бұрын
You’re welcome and thanks for the kind words!
@gallanonim4914
@gallanonim4914 Жыл бұрын
​@@codewitharho Are you planning a WireMock series? I'm very impressed with your approach to the subject of tests. I will definitely recommend this channel further, it's a real gem. Thank you for your amazing work.
@jasper5016
@jasper5016 Жыл бұрын
Wow, this is what I had been looking for, Thanks
@codewitharho
@codewitharho Жыл бұрын
So glad to hear it was useful!
@oolongcc
@oolongcc Жыл бұрын
Good job for explaining concepts in such concise video! I have a question about using constructor injection instead of fields injecton. Could we also use setter injection instead by providing setter methods to inject the dependencies for the repositories (which will be mocked) when writing unit test ?
@codewitharho
@codewitharho Жыл бұрын
You could, but using constructor injection makes sure that the class cannot be modified after instantiation. Using constructor injection also prevents circular dependencies in Spring.
@therealjordiano
@therealjordiano Жыл бұрын
Some rly nice points in here, thanks. my only worry is that in a job where you're using spring, you're likely to get put into a position where you cant just bring in this way of doing things, and you gotta stick to some sort of convention which does force you to use the springboottest annotations. I've just made it through some of them today and it wasn't pleasant, I can't say i love spring anymore
@codewitharho
@codewitharho Жыл бұрын
Well, I guess any framework can and will be abused without some care. Annotations can make it too easy to pick the ”easy” solution if you don’t pay attention. You can always try to point people to informational material, like these videos. 😉
@MrNoxior
@MrNoxior Жыл бұрын
Your videos grew on me) I was wondering what cases we need to check in all the types of tests. Are there some recommendations? For instance, I usually check the correct logic and all the restrictions for database layer tests. What should be tested for service and other tests?
@codewitharho
@codewitharho Жыл бұрын
It largely depends on your architecture. Try to keep technical concerns separated from business logic and then test those in different types of tests. If you are following a layered architecture, then typically the service layer should be mostly about just business logic. The web layer and the database layer are more technically oriented. I have an upcoming article about architecture and testing, so stay tuned!
@MrNoxior
@MrNoxior Жыл бұрын
@@codewitharho I could’ve said the same) I ask about some small thing. It’s hard to explain. It’s more about real case and difficult cases) what should we do if we faced a difficulty? FirebaseAuth is a final class and a bean, and it’s a class one of the dependencies I have) it’s a real hard case I have and I don’t even know how to test)
@codewitharho
@codewitharho Жыл бұрын
I can only suggest creating a wrapper class for difficult dependencies and then mocking that wrapper class instead. Have you watched the 5th video in this series that creates a wrapper for WebClient?
@MrNoxior
@MrNoxior Жыл бұрын
Why do you use an EntityManager in the tests? Isn't it better to use an injected repository?
@codewitharho
@codewitharho Жыл бұрын
TestEntityManager helps you to test the full cycle of storing and retrieving the entity, e.g. flush the persistence context cache and then read the entity from the database. Otherwise the test could just end up reading from in-memory cache.
@stasyty
@stasyty Жыл бұрын
thank you
@codewitharho
@codewitharho Жыл бұрын
You’re welcome!
@jesper7605
@jesper7605 Жыл бұрын
Great content! You cover several useful things I've never heard someone talk about before.
@codewitharho
@codewitharho Жыл бұрын
Thank you!
@francksgenlecroyant
@francksgenlecroyant Жыл бұрын
I immediately subscribed to this channel, so neat, so easy to follow. Keep it up bro!
@codewitharho
@codewitharho Жыл бұрын
Thank you very much!
@ignacioc5177
@ignacioc5177 Жыл бұрын
Moi moi! These videos are beyond excellent, keep them coming Kiitos paljon from Portland, Oregon!
@codewitharho
@codewitharho Жыл бұрын
Moi ja kiitos paljon! 🙏
@rajkrishna1933
@rajkrishna1933 Жыл бұрын
protobuf with rest api java is a topic which has limited resources in youtube.if you can,please add videos on this topic too..
@codewitharho
@codewitharho Жыл бұрын
That’s quite a specific topic and unfortunately don’t have experience on.
@rajkrishna1933
@rajkrishna1933 Жыл бұрын
your videos on testing related code is amazing.frankly there are mo much actual hands on spring test on youtube.please make more such videos
@codewitharho
@codewitharho Жыл бұрын
Thanks, I appreciate that a lot! I have been struggling to find a good work life balance and am currently trying to arrange things so that I can focus more on this channel.
@rajkrishna1933
@rajkrishna1933 Жыл бұрын
your videos on testing related code is amazing.frankly there are mo much actual hands on spring test on youtube.please make more such videos
@codewitharho
@codewitharho Жыл бұрын
Much appreciated!
@p.p526
@p.p526 Жыл бұрын
Sir, please make blog post or tutorial on how to test secure endpoints with JWT token in controller layer testing. And Could you please guild what to do, every answer on stack overflow is deprecated. Could you please help me?
@codewitharho
@codewitharho Жыл бұрын
Thanks for the suggestion! Spring security is quite an important topic.
@p.p526
@p.p526 Жыл бұрын
​@@codewitharho Thanks for the quick response sir. Currently I am disabling the filter (AutoConfigureMockMvc(addFilters = false) ) . Is it right way to do unit testing for the secure endpoints?
@codewitharho
@codewitharho Жыл бұрын
This is quite an extensive topic to discuss in the comments but I would suggest taking a look at the WithMockUser annotation as well as SecurityMockMvcRequestPostProcessors which you can use with the with() method available in MockMvcRequestBuilders. I will consider writing a post about it. Good luck!
@p.p526
@p.p526 Жыл бұрын
​@@codewitharho Thank you sir, It really helps. Sir, only one request please don't stop making tutorials. I have watch tons of videos related to spring and also enrolled in Udemy course. But the content you delivered is 100% to the point, easy to grasp and in depth. Please continue the series related to spring in your channel. And once again Thanks for creating such an awesome series.
@codewitharho
@codewitharho Жыл бұрын
@@p.p526 That is much appreciated. I have been struggling to find a balance between work, life and this channel and am currently trying to arrange things so that I can focus more on this channel. Thanks for the support!
@p.p526
@p.p526 Жыл бұрын
I don't understand the 4th point at 1:29, that It's not unit test if Can't run at the same time as other tests. Do you mean that test should not interdependent? Does my understanding is correct? Or there is some extra meaning of that sentence?
@codewitharho
@codewitharho Жыл бұрын
That’s correct, tests should be independent. If you run them parallel and they affect each other, we are not talking about unit tests.
@divababy2974
@divababy2974 Жыл бұрын
Can I just say I LOVE your background music! And yes what a great video!
@codewitharho
@codewitharho Жыл бұрын
Thank you!
@seantwie0316
@seantwie0316 2 жыл бұрын
I didn't know the trick to add the same package-name in the resources directory. Awesome tip thank you.
@codewitharho
@codewitharho 2 жыл бұрын
Nice! Yes, it’s handy.
@arvinttrigger4501
@arvinttrigger4501 2 жыл бұрын
Simple , Quick , Effective and Informative ...👏👏
@codewitharho
@codewitharho 2 жыл бұрын
Thank you!
@_leftii
@_leftii 2 жыл бұрын
I really don't know how these videos don't have more views. When getting into testing spring boot applications I was so confused because everyone calls it unit testing, I'm now seeing there is a lot more integration testing than unit testing. Thanks for the great series!
@codewitharho
@codewitharho 2 жыл бұрын
Thanks! I’d be happy to get more views but I guess it’s kinda small niche.
@_leftii
@_leftii 2 жыл бұрын
@@codewitharho Yea it's too bad the crowd looking for this stuff is so small. These are by far the best structured and explained of the hundreds I've been though so far. Thanks for sticking to it!
@TomersBu
@TomersBu Жыл бұрын
It takes time - like in real life: a well known store gets a lot of traffic from old customers, while new shops gets less traffic. patience - with time some viewers will like this videos and other videos by @codewitharho and it will promote the channel. It's superb. Love your videos Thank so much. Kiitos (Love Finland as well).
@hendisantika
@hendisantika 2 жыл бұрын
How do we mix testcontainers, mysql & flyway? Do You have article about that? Thanks
@codewitharho
@codewitharho 2 жыл бұрын
I don’t have an article about MySQL specifically but you should be able to follow the article that uses Postgres and just replace the Postgres image with a MySQL image.
@jonathanaplacador9803
@jonathanaplacador9803 2 жыл бұрын
Please create more videos in Spring I learn so much with a short video of yours compared to hours of the same topic.
@codewitharho
@codewitharho 2 жыл бұрын
Thanks a lot! Comments like this really encourage me to keep doing what I like to do.