I feel testing is hard but after watching your video it is nothing and clear for me. Thank you Durgesh sir and please keep making this kind of video, it helps us a lot.
Thankyou so much Durgesh Sir for this video. You explains every concept very clearly. Sir please continue this series of unit testing, it is used by almost every developer and your videos makes a lot of difference in our knowledge.
Hi, Could you please make series for Junit 5 on Login/Registration/List/Update/Delete user based on web application. It will be helpful for us to more understandable. or any other suggestion from your side. Thanks
East side koima,west side kandala, north side Kashmiri, south side kanyakumari ,all side milaake india banta and durgesh bhaiya ko follow karke java developer banta😍😍😍😍
I loved it ! A humble request could u make more videos on junit testing for other functions in spring boot as well?! Like recently u made on spring boot project for 11 hrs something,.
Hi Durgesh, can you please make some series explaining Json libraries? Also which JSON library will be useful in which case? Take a few Json of different types and please explain it.
You actually did not test the real output the function in test. The verify method in mockito just tests that the mocked object's methods were called or not after the test function call. So after verify you have to write some assert conditions as well since we don't know the actual behaviour of the test function. There can be some manipulations as well in that after calling all mocked functions as well.
Agar object mock krne ke bad fir se wo object create ho rha h original class me aur to yha pe to object mock nhi hoga es situation ko kaise handle kiya jaa skta h
You are awesome, I possible. Can you make video with good explanation about the annotation that is used inside the controller like @Pathvariable, @RequestParam things like that.
Hi Durgesh, Thanks a lot for this wonderful video, I am learning a lot from these videos. Could you please clear my below doubt here regarding Mockito, In @Test getAllPersons() { personService.getAllPerson(); verify(personRepo).findAll(); } In above test function personService.getAllPerson(); will give some list and verify(personRepo).findAll(); will give some mocked data for personRepo which is another list, but you have not compared these two list, then how we are testing here exactly, plz help me to understand this, Thanks in advance, and plz keep creating such amazing and useful video, god bless you , Jai Shree Ram...
i am new to unit test i searched in chat gpt You're correct in pointing out that in the test method, we're not directly comparing the data returned by personService.getAllPerson() and the mock personRepo. The test, as written, does not focus on validating the actual data returned by the service; instead, it's focused on verifying interaction with the mock repository. Let me break it down: 1. What the Test is Actually Doing: The current test doesn't check the result of getAllPerson(). Instead, it checks that the findAll() method of the PersonRepo (mocked in this case) is called when getAllPerson() is invoked. This is known as behavioral testing or interaction-based testing. It ensures that when you call getAllPerson() on the service, it behaves correctly by delegating the work to personRepo.findAll(). 2. Why No Comparison is Made: The key point here is that the test doesn't need to compare the lists because its goal is to verify that the findAll() method was called on the mock repository. The mock setup is telling you that the method responsible for fetching data (in this case, findAll()) is called as expected. 3. When to Compare the Results: If you want to test the actual data returned by personService.getAllPerson(), you would need to set up mock data in the PersonRepo and compare it with what is returned by personService.getAllPerson(). How to Compare the List: Here’s how you can modify the test to both verify the method call and check the returned data: Set up Mock Data: You can configure the mock repository to return a specific list of Person objects when findAll() is called. Compare the Result: After calling getAllPerson(), you can compare the list returned by the service with the mock data to ensure they match. Here's an updated version of the test to include result comparison: Modified Test with Data Comparison: java Copy code @Test void getAllPerson() { // Arrange: Prepare mock data List mockPersonList = Arrays.asList( new Person(1, "John Doe"), new Person(2, "Jane Doe") ); // Tell the mock personRepo to return the mockPersonList when findAll() is called when(personRepo.findAll()).thenReturn(mockPersonList); // Act: Call the service method List result = personService.getAllPerson(); // Assert: Verify that the findAll method was called once verify(personRepo).findAll(); // Assert: Compare the returned list with the mock data assertEquals(mockPersonList, result); } Explanation of the Changes: when(personRepo.findAll()).thenReturn(mockPersonList);: This tells Mockito to return mockPersonList whenever findAll() is called on the personRepo mock. This is called stubbing. List result = personService.getAllPerson();: This calls the getAllPerson() method and stores the result in the result variable. assertEquals(mockPersonList, result);: This checks whether the result returned by the getAllPerson() method matches the mockPersonList. If they don’t match, the test will fail. Summary: The original test focuses on verifying interaction (i.e., ensuring that findAll() is called when getAllPerson() is invoked). If you want to test the actual data returned by the service, you need to set up mock data using when().thenReturn() and compare the result using assertions like assertEquals(). This way, you're testing both the behavior and the output of the getAllPerson() method.
Thank you sir for your videos, it helps me a lot but I got one problem if someone can help me how to run individual test case ? in my eclipse it doesn't showing me a green arrow for run individual test case should I need to change anything in setting? please help me
I feel testing is hard but after watching your video it is nothing and clear for me. Thank you Durgesh sir and please keep making this kind of video, it helps us a lot.
East and West Durgesh Bhaiya is the Best. L0ts of l0ve fr0m Ank!t Pathak.
Thankyou so much Durgesh Sir for this video. You explains every concept very clearly. Sir please continue this series of unit testing, it is used by almost every developer and your videos makes a lot of difference in our knowledge.
Bhai Durgesh, all of your videos are really amazing , simple and easy to understand. Thanks a ton. you try to cover a to z all concepts. 👍👍👍👍
Was waiting for this! Great content!
badly needed video on this topic, thank you sir
Hi,
Could you please make series for Junit 5 on Login/Registration/List/Update/Delete user based on web application. It will be helpful for us to more understandable.
or any other suggestion from your side.
Thanks
please make video jMockito also.. much needed series ....
Please make this above series
51:23 This is why constructor injection is preferred to field injection
Exactly.
very oustanding video and gives immense knowledge for learning advance spring boot
Sir important video hai
Best video hai
Thankyou so much Durgesh Sir for this video.god bless u
Clean and clear content super bro tqsm ☺
Best tutorial ever. Thanks Durgesh Sir.
I ended up subscribing your channel. The way you taught is simply amazing 🔥🔥🔥🔥
Great to choose more demanding topics
Sir app to great ho Sunday ko bole aur apne lecture dalbi diya thanks
Crystal clear videos .... Thank you for the detailed exaplaination.
Sir Thankyou so much for these tutorials! ❤️
Very useful and perfectly articulated video. Please upload the further videos too on testing.
Next video please bhut acha lga ye concept clear hue
Sir Thank you for this kind of Knowledge Session..keep it up
Bhai private method ki unit testing kaise kare ispe bhi video banaye. Ye video kamal ka tha apka...Maja aa gya.!
You Are Truly Amazing💚💚 Thanks For Fulfilling My Request🙏🏻 ❣️❣️😍😍
Thanks a lot, Durgesh! It was really helpful! )
East side koima,west side kandala, north side Kashmiri, south side kanyakumari ,all side milaake india banta and durgesh bhaiya ko follow karke java developer banta😍😍😍😍
Ok
acha ok theek h
I loved it ! A humble request could u make more videos on junit testing for other functions in spring boot as well?! Like recently u made on spring boot project for 11 hrs something,.
can you please share the link for that 11 hrs project?
How to testing perform in sts ide any buddy know?
Yes Durgesh , please make next part.
Thank you very much for your precious contribution ........
This is very helpful video 👍 please second part bhi banao sir iska.
Thank you. Please make more videos on this topic.
please make video continue to this video, it will be very helpful.
Please make video on mockito also sir I am waiting for your video please
U r making awesome videos thank u so much ❤️
Aap mahaan ho ❤️
Thanks Durgesh for your support
Eagerly waiting for the next Part......
that's amazing bhaiya lot of love
Bhai next part chaiye ....pls banvo ....nice video
make more videos on JUNIT . you Explained very well
Itne kam Subscribers kyon hain yaar, kam se kam 15-20 lakh to hone chahiye 🥲
Thank you so much sir your videos are really very helpful for every developer
well explained.make part 2 also
1500 se jyada like aa gaye sir next part bana do plz.
Hi Durgesh, can you please make some series explaining Json libraries? Also which JSON library will be useful in which case? Take a few Json of different types and please explain it.
this guy is a legend
Sir mene sare channel dekh liye air par aapse achha koi nhi he sir
Please sir aap logger in java and properties file par bhi video bnaiye sir please
Hello Sir, Can you please make a video on integration testing and other concepts of testing also.
such great explaination👌,can you please explain how to create unit testing for spring controller
bro u can Explan in video about Testing for Springboot application & do along with developing project is more clear for Understanding...🙏🙏🙏🙏
Waiting for the 2nd part of this video !!!!
plzz make more video on testing your channel is university for learning spring
You actually did not test the real output the function in test. The verify method in mockito just tests that the mocked object's methods were called or not after the test function call. So after verify you have to write some assert conditions as well since we don't know the actual behaviour of the test function. There can be some manipulations as well in that after calling all mocked functions as well.
3:37 dependencies
Agar object mock krne ke bad fir se wo object create ho rha h original class me aur to yha pe to object mock nhi hoga es situation ko kaise handle kiya jaa skta h
Hello Sir, please make part 2 also please.
Bhaiya ek complete course on spring boot testing please!
hi durgesh, controller ki testing ka bhi bata do please...
Hello , please continue with series of unit testing.
Hello, please make controller coverage part 2 video plz.
Gajab sir ji
Make videos on Apache Kafka with integration testing. Thanks 🙏
and thank you so much for making this vedio.
Hello durgesh please make second vedio for Unit testing.
Very useful sir thanks a lot
you teach well but begineers ko detail me to btao ye laaye kaha se install kaise hogi use kya hai
Amazing Content
We want microservices real time project bro....
pls make the next parts of series also..in unit testing.
you explain very well but last Mockito example give error in my end and you make separate video on mockito details it will really help us !
Hello Durgesh,
could you please tell how to follow ur channel playlist in order
You are awesome, I possible. Can you make video with good explanation about the annotation that is used inside the controller like @Pathvariable, @RequestParam things like that.
Can you make videos on integration testing in spring boot using rest assured
unit tests should not have database access but you are using it in your code
Hi Durgesh, Thanks a lot for this wonderful video, I am learning a lot from these videos.
Could you please clear my below doubt here regarding Mockito,
In @Test getAllPersons() {
personService.getAllPerson();
verify(personRepo).findAll();
}
In above test function personService.getAllPerson(); will give some list and
verify(personRepo).findAll(); will give some mocked data for personRepo which is another list,
but you have not compared these two list, then how we are testing here exactly, plz help me to understand this,
Thanks in advance, and plz keep creating such amazing and useful video, god bless you , Jai Shree Ram...
i am new to unit test
i searched in chat gpt
You're correct in pointing out that in the test method, we're not directly comparing the data returned by personService.getAllPerson() and the mock personRepo. The test, as written, does not focus on validating the actual data returned by the service; instead, it's focused on verifying interaction with the mock repository. Let me break it down:
1. What the Test is Actually Doing:
The current test doesn't check the result of getAllPerson(). Instead, it checks that the findAll() method of the PersonRepo (mocked in this case) is called when getAllPerson() is invoked. This is known as behavioral testing or interaction-based testing. It ensures that when you call getAllPerson() on the service, it behaves correctly by delegating the work to personRepo.findAll().
2. Why No Comparison is Made:
The key point here is that the test doesn't need to compare the lists because its goal is to verify that the findAll() method was called on the mock repository. The mock setup is telling you that the method responsible for fetching data (in this case, findAll()) is called as expected.
3. When to Compare the Results:
If you want to test the actual data returned by personService.getAllPerson(), you would need to set up mock data in the PersonRepo and compare it with what is returned by personService.getAllPerson().
How to Compare the List:
Here’s how you can modify the test to both verify the method call and check the returned data:
Set up Mock Data: You can configure the mock repository to return a specific list of Person objects when findAll() is called.
Compare the Result: After calling getAllPerson(), you can compare the list returned by the service with the mock data to ensure they match.
Here's an updated version of the test to include result comparison:
Modified Test with Data Comparison:
java
Copy code
@Test
void getAllPerson() {
// Arrange: Prepare mock data
List mockPersonList = Arrays.asList(
new Person(1, "John Doe"),
new Person(2, "Jane Doe")
);
// Tell the mock personRepo to return the mockPersonList when findAll() is called
when(personRepo.findAll()).thenReturn(mockPersonList);
// Act: Call the service method
List result = personService.getAllPerson();
// Assert: Verify that the findAll method was called once
verify(personRepo).findAll();
// Assert: Compare the returned list with the mock data
assertEquals(mockPersonList, result);
}
Explanation of the Changes:
when(personRepo.findAll()).thenReturn(mockPersonList);:
This tells Mockito to return mockPersonList whenever findAll() is called on the personRepo mock. This is called stubbing.
List result = personService.getAllPerson();:
This calls the getAllPerson() method and stores the result in the result variable.
assertEquals(mockPersonList, result);:
This checks whether the result returned by the getAllPerson() method matches the mockPersonList. If they don’t match, the test will fail.
Summary:
The original test focuses on verifying interaction (i.e., ensuring that findAll() is called when getAllPerson() is invoked).
If you want to test the actual data returned by the service, you need to set up mock data using when().thenReturn() and compare the result using assertions like assertEquals().
This way, you're testing both the behavior and the output of the getAllPerson() method.
please please please make one video on FUNCTIONAL TESTING
Great explanation
Thank you bhai for this video
Please create a video on Logging in to Spring boot.
Thanks Durgesh Please do the Amazon S3 service with mockito.
thank you so much sir..........
Sir, please upload videos on mockito on real time examples
Sir I'm beginner I already learn core Java I want to start advance, please give me suggestions me which which one series start first
Learn jsp/servlet or start spring core then spring mvc and spring boot
@@visualart8609 thank you sir
@@visualart8609 without knowing Servlets JSP can learn spring core
Yes
Please create its second part, or please share link if you have already done
Thank you sir for your videos, it helps me a lot
but I got one problem if someone can help me
how to run individual test case ? in my eclipse it doesn't showing me a green arrow for run individual test case
should I need to change anything in setting?
please help me
I am facing the same issue.. is your problem solved 🤔if solved ? can you help me 👈???
Bro next part lekar aaiye please.
Thanks bhai mere kehne per Aapne Unit testing per videos laaye
Thanks sir for amazing video
Part 2 la do sir... Unit testing and mockito par
Hi Durgesh, Can you please show how to write a test case for dataSourceconfig class.
Mockito use karke batao please, bina Autowire kiye
How you take default variable using command?
sir iska next part bhi banao please
instead of giving the google drive file, can you show how to initialize the project, It will be easier.
Please sir make video on
Sonar cube also
Bro pls take microservices p-2, and one microservices project
Please make next video of Mockito with complex logic.
Hello Sir, please create a video on second part also..
Create 2nd part also sir.
If i check with input in a project, i will understand whether it is right or not. Then why do we have to test the unit?
Awesome
Iska next video kb aa raha hai?