This video is my preferred way of unit testing, I hope you guys find it helpful and if you did please drop a LIKE on the video! :) Do you guys use any other frameworks or libraries when unit testing? ide love to know, so drop a comment as well!
verify first if u really need it to be a private method, because if not you could change it to protected, secondly if its a helper method then you dont have to worry about it since your unit test really only cares about what happens when the code executes and you are looking for behavior so let your method that you are testing call out to it and execute and verify the result
If my method is static, what should I do, which means unable test the static method, and I'm using one of the dotnet CMS, so there I'm using CMS API methods, how can we moq those
I might explore doing an integration testing video since you are not the first to reply with that since usually you do not want to unit test a repo or services, thanks! I appreciate the comment and the sub :) Welcome i gotta lotta stuff on the channel and more to come!
Awesome. I asked cause I have a bit crazy api haha with services layer, repository layer and unit of work so would be good to recommend and figure out what we should and what we should not test :o Tnks.
Thank you! appreciate it i try and make my videos useful and not difficult to understand so when it comes to testing the repository methods, you need to look into Integration Testing if you want to learn about how to test that layer because it's much more complicated and takes a lot more moving parts
Hi! Your video helped me a lot! It took me a long time to figure out how to use moq when there are repositories, interfaces, controllers, context, etc. I have already managed to write tests for several methods of methods of the BanksController class. I have a question that I haven't been able to find an answer to yet:( I understand how to use moq with methods that return values and how to make methods raise errors but.... how to use moq with methods that don't return values? I'm writing tests for the Delete method of BanksController class that calls DeleteBankAsync method (which returns nothing) of a BankRepository class. How can I skip that call or substitute it with some custom code? Something like "pass" in Python. Thanks!
Hey im happy to hear my video could help! :) so basically you could just verify on lets say a delete method that one it was called correctly, that indeed that call was made, but there isnt a whole lot u can verify since your repo is being mocked
@@IsraelQuiroz Thanks for replying:) Delete method that I'm testing returns status codes - if there are no exceptions have been caught it should be 204. And I cannot cover this part with my tests because in that part there is a call to DeleteBankAsync and then return OK. Once DeleteBankAsync gets called it throws an error (null reference exception). So I'm stuck and still don't know how to make my test skip this call:( I don't use context in my BanksControllerTests (I'll use it in BanksRepositoryTests when I'll be testing DeleteBankAsync for example), so I wanted to skip this method call in my current tests...
Bro great content and the way you are representing it, but something is odd with the video quality, the light in background and how the camera capture your movement. Please fix that,the content is great but is difficult to watch.