Getting started with Mocking using Moq in .NET (Core, Framework, Standard)

แชร์
ฝัง
  • เผยแพร่เมื่อ 26 ม.ค. 2020
  • Become a Patreon and get source code access: / nickchapsas
    Check out my courses: dometrain.com
    The giveaway is now over. Thanks for participating.
    Hello everybody I'm Nick and in this .NET tutorial I will show you how you can get started with mocking external dependencies in unit testing using Moq. Moq is the most popular mocking framework in .NET and even though it is not my personal favourite, I highly recommend it.
    Moq detailed documentation: github.com/Moq/moq4/wiki/Quic...
    In object-oriented programming, mock objects are simulated objects that mimic the behavior of real objects in controlled ways, most often as part of a software testing initiative. A programmer typically creates a mock object to test the behavior of some other object, in much the same way that a car designer uses a crash test dummy to simulate the dynamic behavior of a human in vehicle impacts.
    Don't forget to comment, like and subscribe :)
    Social Media:
    Follow me on GitHub: bit.ly/ChapsasGitHub
    Follow me on Twitter: bit.ly/ChapsasTwitter
    Connect on LinkedIn: bit.ly/ChapsasLinkedIn
    #dotnet #tests #mocking

ความคิดเห็น • 155

  • @nickchapsas
    @nickchapsas  2 ปีที่แล้ว +3

    Are you looking for more training? Check out my "From Zero to Hero: Unit testing in C#" course: nickchapsas.com/p/from-zero-to-hero-unit-testing-in-c

    • @haskell3702
      @haskell3702 ปีที่แล้ว

      Hi, how can I verify a protected method call using DI?
      when I use var mock=new Mock
      and try setup the protected with mock.Protected().Setup("MyMethod") I get a error: "No protected method found", but the method exists and it is virtual
      but if I use var mock=new Mock it works but this way is not acceptable for my project, you know

  • @rvranny
    @rvranny 4 ปีที่แล้ว +90

    My day today:
    1. Tried to understand Mocking over the Internet: > 6 hours 😟
    2. Took a nap: 30mins 😴
    3. Finally learnt through this video: 20mins 🙂
    4. Subscribed:1sec 🤘
    Thank you Nick, please go for advance xUnit and Moq.

    • @nickchapsas
      @nickchapsas  4 ปีที่แล้ว +6

      That is so great to hear Ranvir! Glad I could help 😃

    • @_Anherius_
      @_Anherius_ 4 ปีที่แล้ว +1

      same here!!!! thanks Nick!!

    • @nelsonfabianriosdeantonio6211
      @nelsonfabianriosdeantonio6211 4 ปีที่แล้ว

      Yeah this guy is a good teacher.

    • @rajaniupadhyay7875
      @rajaniupadhyay7875 2 ปีที่แล้ว

      Same here

    • @subhraswarup
      @subhraswarup 2 ปีที่แล้ว

      Hey same here. Now I understood. Can’t express my happiness. A big relief. Thanks

  • @vmamore
    @vmamore 4 ปีที่แล้ว +26

    An advanced video would be awesome, Thanks Nick!

  • @vishalbalani7692
    @vishalbalani7692 3 ปีที่แล้ว +1

    Thank you Nick, I always had hard time with mocking test cases but finally I was able to successfully mock and fix the test cases which were having problem. Thanks a lot!!

  • @justraccoon3047
    @justraccoon3047 2 ปีที่แล้ว

    Omg, bro. I had tried to understand it with lots of mistakes for 4 hours, but you just explained it in 20 minutes in a simple way. Thanks a lot!)

  • @digimonsta
    @digimonsta 3 ปีที่แล้ว +3

    Loving these videos. Short enough and in sufficient detail to grasp the basics quickly, without having to devote hours at a time.

  • @AhmedRaza-ru1rj
    @AhmedRaza-ru1rj 2 ปีที่แล้ว

    I spent hours figuring out why I was getting NullReferenceException as I just started learning and using moq. Your video covered the exact scenario. Thanks, mate

  • @yaknad
    @yaknad 4 ปีที่แล้ว +1

    Great video, as always. Straight to the point, very clear and thorough. Thanks Nick!

  • @harikakiran18
    @harikakiran18 4 ปีที่แล้ว +6

    Great material, thanks Nick for putting this together. Appreciate it! Looking forward to see advanced videos especially eliminating the external dependencies like database, network, api calls etc. with some mocked data. You have got great content on your channel, sub'ed. Will spend some time, thank you.

  • @arwwarr7578
    @arwwarr7578 2 ปีที่แล้ว

    You're just the best, you can explain anything in a perfectly understandable way.

  • @sunilanthony17
    @sunilanthony17 4 ปีที่แล้ว

    Thank you, Nick. I tried both and love Moq better. I'm sticking with it.

  • @ppriyadarshini81
    @ppriyadarshini81 หลายเดือนก่อน

    I was literally tired watching videos on Nunit but this is "THE" best explanation !! hats off to you efforts.. !!

  • @rishikeshkumar8141
    @rishikeshkumar8141 3 ปีที่แล้ว +1

    Very well explained with real examples. Awesome!

  • @michaelkopljan578
    @michaelkopljan578 4 ปีที่แล้ว

    Thanks Nick for all your videos!

  • @argelpamintuango1956
    @argelpamintuango1956 4 ปีที่แล้ว

    this video saves me
    !
    very easy to understand on the Moq usage
    thanks Nick!

  • @react_33
    @react_33 3 ปีที่แล้ว

    I was like nah imma head out from testing part and then I found this video. 30 mins and all good. thnx mate.

  • @thesuperiorman8342
    @thesuperiorman8342 3 ปีที่แล้ว

    I watched this first before knowing anything about mocking but I didn't understand much. I then read a beginner friendly article that gave a very simple introduction and then later came back to watch this video and it all makes sense now. Your examples are helpful because they are real world which is what I need for my project.

    • @nickchapsas
      @nickchapsas  3 ปีที่แล้ว +1

      Yeah I got that feedback quite a bit. So the assumption of the video is that the viewer already understands the concept of mocking, in order to keep the video length smaller, but it might be harder for complete beginners.

  • @GrahamStw
    @GrahamStw 3 ปีที่แล้ว +4

    Nice video. thanks.
    Small point: some viewers might be tempted to put the creation of the Mock instances at the class fixture level (e.g. in an IClassFixture for xUnit). Don’t do that because the Mock contains state information (which Setups exist, what has been called, what was Verified), so a new Mock instance should be created for each test case.

  • @JR-zv7ws
    @JR-zv7ws ปีที่แล้ว

    Thanks for the video Nick, it was just what i was looking for :)

  • @hansikachowdary4581
    @hansikachowdary4581 3 ปีที่แล้ว

    Great video nick! Helped a lot.

  • @rossthemusicandguitarteacher
    @rossthemusicandguitarteacher 3 ปีที่แล้ว

    Very good explanation
    :)

  • @RavindraKumar-dh6dn
    @RavindraKumar-dh6dn 4 ปีที่แล้ว

    Awesome !! Great video to understand, how to write test case
    Well explained

  • @sherifmankarious88
    @sherifmankarious88 3 ปีที่แล้ว

    Thanks for sharing, yes an advanced is indeed needed.

  • @sagarpatil5997
    @sagarpatil5997 2 ปีที่แล้ว

    Very nice explanation Nick.. Keep it up...!!

  • @sherazdotnet
    @sherazdotnet 2 ปีที่แล้ว

    1+ to naming convention on class name. Very handy. I haven't used Rider (in fact didn't even know about it) but I use Resharper in VS and one very handy feature is to see the list of all the files by pressing Ctrl + N. Now when you name a test file as a convention of Object + Test, it becomes very easy to find the tests. If I have a TradeBookingViewModel class, I can have a TradeBookingViewModelTests and just like that, when I type TBVM in Ctrl+N window, it will pop both classes showing actual class and the tests for that class.

  • @salarkazazi7584
    @salarkazazi7584 2 ปีที่แล้ว

    Thank you so much, very informative and well explained :-)

  • @anamariacompany1920
    @anamariacompany1920 2 ปีที่แล้ว

    Great demo!!!

  • @yessenzhol8989
    @yessenzhol8989 11 หลายเดือนก่อน

    Great tutorial! Thanks!👍

  • @TroyMakesGames
    @TroyMakesGames 4 ปีที่แล้ว

    Fantastic video! Thanks

  • @iryzen9673
    @iryzen9673 ปีที่แล้ว

    Thank you so much! You helped me a lot!

  • @davido.7991
    @davido.7991 ปีที่แล้ว

    Great video, very helpful!

  • @jakubczechowski1159
    @jakubczechowski1159 2 ปีที่แล้ว

    Thank you for the video!

  • @nishthaarora1907
    @nishthaarora1907 2 ปีที่แล้ว

    very good explanation..thanks!!

  • @serhiihorun6298
    @serhiihorun6298 4 ปีที่แล้ว

    Great work!

  • @vitaliykoritko5080
    @vitaliykoritko5080 3 ปีที่แล้ว

    Good video, but better to use conrete value or Is instead of IsAny

  • @GBG731
    @GBG731 3 ปีที่แล้ว

    hallo Nick, Thanks for the tutorial,

  • @fatemehfathollahi1921
    @fatemehfathollahi1921 2 ปีที่แล้ว

    Thank you for this useful video

  • @alisadeghi3642
    @alisadeghi3642 2 ปีที่แล้ว

    excellent tutorial

  • @hvndev476
    @hvndev476 2 ปีที่แล้ว

    Nice. Thank for sharing

  • @zohashobbar118
    @zohashobbar118 ปีที่แล้ว

    that was grate, thanks

  • @andriyzubyk629
    @andriyzubyk629 4 ปีที่แล้ว

    Thanks Nick

  • @shuvo9131
    @shuvo9131 2 ปีที่แล้ว

    thanks for the video, I love it.

  • @alevsoft
    @alevsoft 4 ปีที่แล้ว

    Like and a Subscription. Great rapid walkthorough. Thank you!

  •  3 ปีที่แล้ว +1

    Congratulations for you video, I was looking for this project in your git hub repository but I didn't found it . I would like to check it .

  • @joelvilabringuez7162
    @joelvilabringuez7162 ปีที่แล้ว

    Excellent

  • @redachouiba4862
    @redachouiba4862 4 ปีที่แล้ว

    Good job, we are waiting the next video about NSubstitute & fake ...

  • @ursmuller5545
    @ursmuller5545 2 ปีที่แล้ว

    Thanks 👍

  • @vabhs192003
    @vabhs192003 4 ปีที่แล้ว +1

    Nick: Any specific reason to pick the Xunit over NUnit? Loving your videos. Please keep posting new stuff. Your playlist is a treasure trove of complex concepts made simple. Already a subscriber. :)

    • @robertsnyder4480
      @robertsnyder4480 2 ปีที่แล้ว +1

      I just had a talk at work on this very subject. Even though I used to contribute to NUnit, I'm here to tell you that it really doesn't matter between xUnit, NUnit, or MsTest v2. There is very little that you can't do in one over the other. If you refer to Nick's video on Nuget packages you should use he also mentions getting FluentAssertions which makes the argument of you prefer the way assertions are written in one framework over another. We went with xUnit at my current client because it keeps with the mentality of writing helper classes in your test projects that you can pass into the ctor just like you would with production code.

  • @emilgebl8644
    @emilgebl8644 2 ปีที่แล้ว +1

    Regarding the log information, what if you use dependency injection and sent the logger in as Ilogger Logger? do you mock it then? how could you compare it then like at 19:12

  • @mikolajsemeniuk8574
    @mikolajsemeniuk8574 3 ปีที่แล้ว

    great video

  • @JohnSourvinos
    @JohnSourvinos 2 ปีที่แล้ว

    Greetings from 39°38'N / 19°55'E. In the GET method (around 11:30 - line 28) you provide the expected response as a CustomerDto object. Later in the Assert (line 41), the customerId is compared with the CustomerDto's Id. Since the call to the service is fake and no 'real' data is fetched, what is the point of comparing two things that are by definition equal? Unless this test is done only to increase the code coverage, can you please give us a good reason for testing the GET method?

  • @viniciussantosaguiar9543
    @viniciussantosaguiar9543 4 ปีที่แล้ว

    Super good! It helps me a lot!!!

  • @SantyaRocks
    @SantyaRocks 2 ปีที่แล้ว

    Hi Nick
    Hope you're doing well. I watched your all xunit video
    I'm struggling for writing unit test using xunit framework. One for the method is inserting records into SQL db. I have written unit test case for this method but in the end cmd. executenonquery throwing exception like below
    "BeginExecuteNonQuery requires an open and available connection. The connection currently state is closed"
    I believe I need to mock sqlconnection. Any suggestions. Appreciated

  • @bigboy3775
    @bigboy3775 ปีที่แล้ว

    Thx for this toturial! I have a question, how do I see the code coverage? I don't have the right-click option to "View Code Coverage"

  • @Bikramkumarsahoo1988
    @Bikramkumarsahoo1988 4 ปีที่แล้ว

    What kind of extensions are you using while writing code in vs code tool.

  • @ravibugude1934
    @ravibugude1934 2 ปีที่แล้ว

    it was a great session. How can we mock a external library extension extension methods using mock and XUnit

  • @hchattaway
    @hchattaway ปีที่แล้ว

    This is a great video and answered a lot of questions.. but i still have one which may be a stupid question! :)....
    If a method is being setup as shown and you specify what it shall return, the underlying implementation is still not actually being called right? it seems like you're telling it what to return so the test will always pass.... that is unless of course the actual implementation is being called somehow.. but I don't see that...
    Could you clarify this confusion? Thanks!

  • @piotrc966
    @piotrc966 4 ปีที่แล้ว +9

    Yes, we want advanced :).

  • @luisbragado171
    @luisbragado171 2 ปีที่แล้ว

    Excellent example and you have a great pronunciation for a mexican, thank you very much ... subscribed!

  • @andersonpaolo2202
    @andersonpaolo2202 4 ปีที่แล้ว +2

    Hi Nick, thank you for your video's. Can you put your code her please, i can't find it in your link

  • @kostasntou8649
    @kostasntou8649 4 ปีที่แล้ว

    Ωραίος !

  • @nadaralpenidze9549
    @nadaralpenidze9549 3 ปีที่แล้ว +3

    Hey Nick, amazing video.
    I have one question,
    If my purpose is testing GetUserById and I create a mock which returns a value I'm deliberately giving to it, how does it benefit my test?
    I won't know if my actual service works, I know that the mock works.
    Am I missing something?

    • @JustMe-hv5re
      @JustMe-hv5re 3 ปีที่แล้ว +3

      I would say no, I have asked this question repeatedly to people who promote it and the only benefit is testing exceptions/testing for nulls. This will not test data type matching for parameters, missing parameters being passed to stored procedures, columns coming back lining up (ie assigning them to the actual class property coming back and referencing it), or that stored procedure names are correct. As far as I am concerned this a waste of time and repos really need integration testing to a test db.

    • @Psykorr
      @Psykorr 2 ปีที่แล้ว +2

      Agreed. Use mocks for the things around the db calls, and actually test bd calls with some tool like postman or some sql program like sql server management studio or whatever on test bd's. I've seen real problems with calling systems that only use mocks for testing db calls. Often they don't work and real people are affected by it.

    • @robertsnyder4480
      @robertsnyder4480 2 ปีที่แล้ว +1

      Along the same words as the first 2 replies I'd treat db calls like any other external system. Make the mock return reasonable data that you would legit see (or portions of it). knowing what your external service is going to return is part of the leg work of Proof of concept projects or having a integration test project that only runs locally to test these data structures. Just know that those tests are usually brittle and break easily and are hard to understand usually.

  • @priyanshu4016
    @priyanshu4016 3 ปีที่แล้ว

    did covered unit test will also work for visual studio?

  • @whateverman3846
    @whateverman3846 4 ปีที่แล้ว

    Nice tutorial but the link in desc didnt take me to source code, is there a direct link ?

  • @khaledslaimia3135
    @khaledslaimia3135 3 ปีที่แล้ว

    good video dear sir.but i have a problem,i work with automapper and the controller return null.it seems that the autommaper should be inciated only one time.can yo help me with that

  • @Tajemniczy
    @Tajemniczy ปีที่แล้ว

    Hey, big thanks for the video:) now all is more understandable, I just starting playing with unit tests.. I have one question, can you tell me how you have aaa autocomplete it (Arrange Act Assert) ?:) thanks
    PS. For right now I make it snippet file and manually I'm adding this into visual studio and it's working fine but maybe is some already nuget with this function:)?

    • @nickchapsas
      @nickchapsas  ปีที่แล้ว

      I have my own code template that implements that for me in rider

    • @Tajemniczy
      @Tajemniczy ปีที่แล้ว

      @@nickchapsas aa ok:), the same day I tried to find an extension to visual studio that would have such functionality, but unfortunately I did not find anything, so I decided to see if it is hard to create such an extension with such functionality and I sat up all night and managed to create such a thing, it now generates me AAA (Arrange, Act, Assert) and test methods that contain it, if you want it you can find in the marketplace under the name AAASnippet including documentation ;d. It's not some mega awesome, it's my first, but it does what it's supposed to do :) "AAASnippet"

  • @marekk9008
    @marekk9008 3 ปีที่แล้ว +1

    I would also like to watch a video about an advanced usage

  • @QuickZ_
    @QuickZ_ ปีที่แล้ว

    Very nice job again, sensei!
    But I hope people dont start returning null as a result. Null should mean "I dont know" if anything. You already know this Nick since you made videos about better ways. Just putting it out for the people. To many use null as a valid value.

  • @nelsonfabianriosdeantonio6211
    @nelsonfabianriosdeantonio6211 4 ปีที่แล้ว

    Awesome

  • @olayemiafolabi2151
    @olayemiafolabi2151 4 ปีที่แล้ว

    Hi Nick, I am interested in the advanced tutorial on unit testing

  • @seacprogrammer8455
    @seacprogrammer8455 4 ปีที่แล้ว +1

    WHERE IS THIS SOLUTION ON YOUR SOURCES REPO WHATS IT NAMED ?!

  • @atifsaeedkhan9207
    @atifsaeedkhan9207 ปีที่แล้ว

    Hey man, would you please send me link in which you discussed the Microsoft logger for dot net core web api. thanks in advance

  • @haskell3702
    @haskell3702 ปีที่แล้ว

    Hi, how can I verify a protected method call using DI?
    when I use var mock=new Mock
    and try setup the protected with mock.Protected().Setup("MyMethod") I get a error: "No protected method found", but the method exists and it is virtual
    but if I use var mock=new Mock it works but this way is not acceptable for my project, you know

  • @yaaanakutty8212
    @yaaanakutty8212 2 ปีที่แล้ว

    Hai can you please tell me how to return only response and how to return null and nonull in xunit

  • @TheRabinarayan
    @TheRabinarayan 4 ปีที่แล้ว +2

    unable to download the source code.pls help

  • @mikolajsemeniuk8574
    @mikolajsemeniuk8574 3 ปีที่แล้ว

    where is the link to repo and how can we mock DataContext?

  • @brahmcdude685
    @brahmcdude685 3 ปีที่แล้ว

    14:41 ".Returns(() => null);" - I built this example using non-async. I still got an error for this: ".Returns(null);". Here is the error: "CS0121 The call is ambiguous between... 'IReturns.Returns(TResult)' and 'IReturns.Returns(Func)'". Using ".Returns((CustomerDto)null);" also resolves this error.

  • @jfpinero
    @jfpinero 3 ปีที่แล้ว

    I didn't watch the whole video but when creating your mocks, you should specify MockBehavior.Strict or whatever it is to make sure you are not calling something you didn't intend.

  • @mohanalingamp3178
    @mohanalingamp3178 ปีที่แล้ว

    Hi Nick, you are doing a great job man. Same way I would like to know about Nunit testing for the concepts like dependency injection, API request and responce, etc. Hope you will see and make videos for it.

  • @devikasiddani
    @devikasiddani 3 ปีที่แล้ว

    how to implement if code not using of DTO

  • @koryphaee4796
    @koryphaee4796 4 ปีที่แล้ว +2

    I think NSubstitute is the much better mocking framework. The code is so much more readable and easier to understand.

    • @nickchapsas
      @nickchapsas  4 ปีที่แล้ว +5

      I totally agree with you as well. I am personally using NSubstitude and the next video is about that. I needed to show how NSub improves upon Moq so I had to show Moq first before I show NSub.

    • @koryphaee4796
      @koryphaee4796 4 ปีที่แล้ว +1

      @@nickchapsas Alright that makes sense. Looking forward to that next video. Btw your Blazor video series helped me a lot.

  • @MikeBSc
    @MikeBSc 2 ปีที่แล้ว

    You haven't shown how to include the Moq libraries. I put "using Moq;" at the top of my test class and says it can not be found.

  • @EricOnYouTube
    @EricOnYouTube 3 ปีที่แล้ว

    How did you get the aaa to expand to Arrange Act Assert?

    • @nickchapsas
      @nickchapsas  3 ปีที่แล้ว

      I have created a template for it in JetBrains Rider so I just to aaa and press Tab and it creates it for me

  • @HidayetArgandabi
    @HidayetArgandabi 3 ปีที่แล้ว

    could you please share the project link

  • @shaunhunterit342
    @shaunhunterit342 11 หลายเดือนก่อน

    Your Github repo for this app has over 2000 commits. Which commit should we download for this video?

  • @LonliLokli
    @LonliLokli 3 ปีที่แล้ว

    Thing I missing is Moq + Dapper in terms of splitOn

  • @rs3800
    @rs3800 2 ปีที่แล้ว

    have you guys ever encountered problems with visibility to MOQ? does not work for me to .Setup(), whereas it works fine with for the rest of the Test but not for setting up MOQ.

    • @robertsnyder4480
      @robertsnyder4480 2 ปีที่แล้ว

      not personally. The only time I've done this is when I've mocked HttpClient (well the handler that gets passed into the ctor). It only has a protected member that you have to override. There is a contribs nuget package to help with this but you can also define an interface and use the .Internal().As() or .Protected().As(). I find this easier to deal with as long as I know the hidden signature won't change.

  • @steveo600rr
    @steveo600rr 4 ปีที่แล้ว +4

    I don't see the github repo?

  • @usamesavas9848
    @usamesavas9848 ปีที่แล้ว

    I really don’t understand copy-pasting the exception message inbetween the test and the method implementation. This is one of the things about unit testing which does not sound quite right to me. I don’t know if there is a better way, though.

  • @markopavlovic6066
    @markopavlovic6066 3 ปีที่แล้ว

    Helloo my brother when I want to display triple aaa like you there is no snippet for that, can you tell me how to do it?

    • @nickchapsas
      @nickchapsas  3 ปีที่แล้ว

      I created a Live Templates using my Rider's feature. It's different based on the IDE that you are using. In Visual Studio it's called Snippets.

  • @zeljkobilandzija1748
    @zeljkobilandzija1748 4 ปีที่แล้ว

    Great learning material. It would be great if we can find and download source code.

    • @nickchapsas
      @nickchapsas  4 ปีที่แล้ว

      You can find the source in the video description

  • @enissay9950
    @enissay9950 ปีที่แล้ว

    Hi Nick, amazing video as usual.
    I tried to add the shortcut aaa to generate my fact method, but I failed miserably. I have successfully added it to the LiveTemplates, but teh shortcut is not working in the Unitest context, not sure how to configure that :-/
    Which brings me to a request: can you have a video to show your favorite custom templates, and maybe other Rider tricks as well as how to set that up

    • @user-bd3zz6gq4f
      @user-bd3zz6gq4f ปีที่แล้ว

      you can add it to live templates in rider. Don't forget add space before //. In my case, without space it doesn't work

  • @pedramfeyz2173
    @pedramfeyz2173 4 ปีที่แล้ว

    Great job, Advanced video, please

  • @limsky8012
    @limsky8012 2 ปีที่แล้ว

    How to test controllers?

  • @pavfrang
    @pavfrang ปีที่แล้ว

    Unfortunately the behavior with ILogger and extension methods (LogDebug, LogInformation) is not supported. You have to write the plain Log method which is quite big and almost impractical.
    I suspect that's why you wrote a "generic ILoggingService" and not the standard ILogger.

  • @uakrongrad
    @uakrongrad 2 ปีที่แล้ว

    great video, sorry I'm having trouble locating the source code for the project demo'd. I do not see a direct reference, nor indirectly from the git hub link. please add it. TYVM

    • @nickchapsas
      @nickchapsas  2 ปีที่แล้ว

      The first line in the description will point you to the code

  • @somnathkadam1233
    @somnathkadam1233 2 ปีที่แล้ว +2

    can please share source code link?

  • @CG-xl4tu
    @CG-xl4tu ปีที่แล้ว

    I see some example use [Test] instead of [Fact] with Moq, can anyone explain?

    • @gavinsmith9033
      @gavinsmith9033 4 หลายเดือนก่อน

      I don't know why this question doesn't have a response (or why I'm here! Thought process was, "are people still using Moq?"). Anyway for anyone else that stumbles across it. Those attributes are not part of Moq they are the testing framework, [Fact] is xUnit, [Test] possibly nUnit, [TestMethod] for example is MSTest. Hope that helps somebody.

  • @zerosandones7547
    @zerosandones7547 2 ปีที่แล้ว

    is the _sut naming convention a standard when doing a test?

    • @robertsnyder4480
      @robertsnyder4480 2 ปีที่แล้ว

      I don't think it's standard however I've seen it a fair number of times and do it myself.

    • @zerosandones7547
      @zerosandones7547 2 ปีที่แล้ว

      @@robertsnyder4480 I think I'll get used to _sut instead of _concreteClass right 😆

  • @sherazdotnet
    @sherazdotnet 2 ปีที่แล้ว

    Quick Question: Why are you using constructor in test class? Not sure which testing framework you are using but I think it should have a Setup attribute or something similar that you can decorate your method which will make the framework run the method every time a new test is run. Wondering why you decided to use constructor instead?
    Update: figured it out. you are using XUnit and here is what they say
    [SetUp] [TestInitialize] Constructor We believe that use of [SetUp] is generally bad. However, you can implement a parameterless constructor as a direct replacement. See Note 2
    Cool.

    • @nickchapsas
      @nickchapsas  2 ปีที่แล้ว +2

      Nah that’s not needed in xunit it’s unnecessary. The pattern with xunit is constructor for setup and dispose method for tear down which is way cleaner

    • @sherazdotnet
      @sherazdotnet 2 ปีที่แล้ว

      @@nickchapsas yep agreed. I updated my comment as well showing what xUnit says.