Mock Service in RestController and Writing JUnits for POST with MockMvc | Tech Primers

  Рет қаралды 39,719

Tech Primers

Tech Primers

Күн бұрын

Пікірлер: 46
@navalgupta9545
@navalgupta9545 6 жыл бұрын
Thanks for the simplest explanation of mocking rest services using Sprint Junit Runner.
@TechPrimers
@TechPrimers 6 жыл бұрын
thanks naval
@vamshikrishna8143
@vamshikrishna8143 6 жыл бұрын
power mock for static and private methods would be a great addition.
@navidgalt2244
@navidgalt2244 6 жыл бұрын
Very nice video! Can you show how to create tests for a POST method for REST services (passing headers and a body) with SpringMVC?
@shruthishru3553
@shruthishru3553 2 жыл бұрын
Very helpful, easy to understand, thanks 😊
@sureshdhulipudi600
@sureshdhulipudi600 5 жыл бұрын
How to mock Rest Template, i.e in service layer we r consuming rest end point
@abhilashsulibela1414
@abhilashsulibela1414 6 жыл бұрын
Awesome content. Please keep making more!
@tw5529
@tw5529 3 жыл бұрын
Awesome 👍😊 . If there will be a Controller Interface and all the methods iside Interface will be annotated with @GetMapping or @PostMapping . Controller class implements that Controller Interface.Then what exactly do we need to make change here??
@lalitkulkarni6768
@lalitkulkarni6768 6 жыл бұрын
Not all post methods return back some json. Thus it becomes important to understand how to write a junit test in a scenario when we have a post method which inserts some data in the database by the route Rest controller --> Business --> Repository. This method doesn't return back any data. Can you please mention what should be the assertions or checks in this case? And what needs to be mocked in such cases.
@AshishGupta-rh3jf
@AshishGupta-rh3jf 6 жыл бұрын
I was struggling to write test cases for services. Thanks a lot for this video. Can you help to prepare for C# restful services testing.
@rossayer7729
@rossayer7729 3 жыл бұрын
The music listed in the description is not what I'm hearing in the video. Where do we find the song playing in the video? Edit: Found it in another Tech Primers video: Lowrider, Luvly - Joakim Karud
@VivekSharma-qs6qp
@VivekSharma-qs6qp 5 жыл бұрын
Hi dude. At 2:48 You show that how we can use thenReturn() method to provide the response of the helloService.hello() method. In my case, I have a custom object that is being returned instead of a plain string. How to specify it in the thenReturn method?
@raaghaviravisankar1853
@raaghaviravisankar1853 3 жыл бұрын
How is it returning hello it should return hello world right since it specified in service?
@koushivlogs77
@koushivlogs77 5 жыл бұрын
Hi..excellent tutorial for beginners. Please create video on 100 percentage test coverage for a pojo annotated with lombok
@jasper5016
@jasper5016 3 жыл бұрын
Its good information but can you cover Mockito testing of CRUD operations? It would super helpful
@kirann9433
@kirann9433 4 жыл бұрын
how to write test case for multipart file as input for post request parameter
@basmaradadi9155
@basmaradadi9155 5 жыл бұрын
Hi , in ur folder's project in github it missed some files (like the model ..) please check it thnks
@jsloth0303
@jsloth0303 4 жыл бұрын
awesome video !
@narasimhareddy0907
@narasimhareddy0907 6 жыл бұрын
Can you provide junit for jdbctemplate with mockito
@richardlanglois5183
@richardlanglois5183 6 жыл бұрын
Very useful presentation!
@1mallareddy
@1mallareddy 5 жыл бұрын
Can anyone help me in, how to add headers, params to the request if possible including basi auth? Any videos/link is appreciated, Thanks in advance :-)
@bhargavkommu9423
@bhargavkommu9423 7 жыл бұрын
Hi.. can I request you to give an example on power mock for static and private methods
@TechPrimers
@TechPrimers 7 жыл бұрын
sure. will do bhargav.
@dileepalla6769
@dileepalla6769 7 жыл бұрын
can u post an example on how to perform logging in spring mvc ,hibernate and create a war file and deploy into server and junit test cases and add to hoe to add repository svn or git post one bigger example
@TechPrimers
@TechPrimers 7 жыл бұрын
Sure Dileep. I will do one soon.
@ainuddinb
@ainuddinb 7 жыл бұрын
Very useful :) Thank you.
@TechPrimers
@TechPrimers 7 жыл бұрын
thanks ainuddin
@gaurav-javatechgeek935
@gaurav-javatechgeek935 4 жыл бұрын
could you plese provide more vieos like crud operation Mock testing for Rest controllers?
@JohnWick-zc5li
@JohnWick-zc5li 7 жыл бұрын
thanks for vidoes -- how mock a final class, interface, & static method..
@TechPrimers
@TechPrimers 7 жыл бұрын
+John Wick you can use PowerMock to do that. I will see if I can do a video on that
@javatar4809
@javatar4809 7 жыл бұрын
Please make videos on testing RestController in spock framework...
@TechPrimers
@TechPrimers 7 жыл бұрын
Sure Javatar, Will do
@mudassir3174
@mudassir3174 6 жыл бұрын
Hello sir, please show how can we check for XML
@TechPrimers
@TechPrimers 6 жыл бұрын
sure
@yqevawang1864
@yqevawang1864 7 жыл бұрын
Nice post!
@TechPrimers
@TechPrimers 7 жыл бұрын
Thanks yqeva
@midasama3124
@midasama3124 4 жыл бұрын
It looks pretty straightforward with dummy JSON files, but I would love to see a video with a real database!
@lajos-berenyi
@lajos-berenyi 4 жыл бұрын
Hi Miguel! What you are asking for is not anymore a Unit test, but functional test, what can be done mostly with selenium, or trying the application with postman, etc. The Unit test is testing only a logic of a particular method of particular class. For example in his case we just testing the logic in the methods of the HelloResource class. Here we don't test the logic placed in the dependencies, so we here just mock them and only check if they where called (verify in the video). If we would like to test the logic in the HelloService, we make the separated test class for that, where we only test the logic in the HelloService, etc. So similarly if we use a Dao or Repository for DB operations, in the Unit test we don't really connect to the DB, we only mock the Dao or the Repository class, but we can check if their methods are properly called.
@midasama3124
@midasama3124 4 жыл бұрын
​@@lajos-berenyi Hi Lajos. I really appreciate your extensive and fully descriptive explanation. I am still struggling with these concepts regarding software testing. I get your point that my request gets out of the scope of unit testing, but I just don't see the point of testing simple CRUD operations (at least in my case) on a DAO or JDBC template mock. I would rather just skip that and test the overall functionality on a real database. For the moment, I just don't know to what extent unit testing may become rather unnecessary, and when it would be good practice to implement it.
@lajos-berenyi
@lajos-berenyi 4 жыл бұрын
@@midasama3124 I will write a simple example of CRUD Unit test (the unit test is testing the logic and not the data), for exsmple the Create method: we mock the repository and checking if in the post controller method the repository's save method was called with the correct parameter, and checking the correct answer of the post method. Also we write a test, that if the repository throw an exception (means the data isn't saved to the DB), the post method also throw an exception or check that despite of saving exception the post method doesn't throw an exception but will answer with not 200 status, but with some 400+ status and give answer some errorResponse json. This how the unit test works in practice.
@lajos-berenyi
@lajos-berenyi 4 жыл бұрын
@@midasama3124 Here is a code example, what I was talking about: drive.google.com/file/d/1CF8KN9acbWAmFSMzHtfXDVn4-gJTGnX7/view?usp=sharing
@smithdragon6477
@smithdragon6477 4 жыл бұрын
Why not wiremock
@smithdragon6477
@smithdragon6477 4 жыл бұрын
I was struggling with wiremock and this way to mock rest
@tarunsapra1930
@tarunsapra1930 7 жыл бұрын
Hello guys, Nice video but you have used an old technique to test controlllers. Spring boot offers much easier and more intutive way to test the Controllers. Just use the annotation @WebMvcTest and for mocking the service just use @MockBean annotation and @WebMvcTest also auto-configures MockMvc which offers a powerful way of easy testing MVC controllers without starting a full HTTP server.
What is Spock? | Specification Tests | Tech Primers
8:54
Tech Primers
Рет қаралды 6 М.
СОБАКА ВЕРНУЛА ТАБАЛАПКИ😱#shorts
00:25
INNA SERG
Рет қаралды 3,6 МЛН
ТЮРЕМЩИК В БОКСЕ! #shorts
00:58
HARD_MMA
Рет қаралды 1,5 МЛН
The IMPOSSIBLE Puzzle..
00:55
Stokes Twins
Рет қаралды 103 МЛН
REST API Documentation using Swagger2 in Spring Boot | Tech Primers
26:27
Unit and Integration Tests in Spring Boot JPA Example | Tech Primers
14:00
Perform HTTP GET and POST Requests MockMvc to Test a @RestController
10:11
Spring Security using OAuth2 in Spring Boot | Tech Primers
1:00:37
Tech Primers
Рет қаралды 264 М.
Mockito Tutorial - Mocking With Junit and Maven
1:11:53
in28minutes
Рет қаралды 552 М.
Mockito JUnit Example
18:53
Telusko
Рет қаралды 332 М.
СОБАКА ВЕРНУЛА ТАБАЛАПКИ😱#shorts
00:25
INNA SERG
Рет қаралды 3,6 МЛН