i fell for mocks again...

Поділитися
Вставка
  • Опубліковано 21 лис 2024

КОМЕНТАРІ • 134

  • @walker_0924
    @walker_0924 Місяць тому +151

    Yeah ads is fine, I trust your integrity enough that ads would probably be a sort of "recommendation" or like "hey take a look at this cool stuff" It helps pay the bills for my favourite creator as well so, do what you do mustache man. Love your content

  • @hiyabobb
    @hiyabobb Місяць тому +53

    Mocks - poking holes in reality for short term convenience and hoping things will be close enough.

  • @travisnapier71
    @travisnapier71 Місяць тому +56

    I'm loving this new content format. Succinct and informative. Testing is a blind spot for me and I'm appreciative of you sharing your experience with them.
    Definitely throw in their some ad reads in these videos. I feel you respect your audience enough to make sure that the tech you're promoting is authentic and legit.

  • @nic122583
    @nic122583 Місяць тому +17

    I do both types of testing. Unit testing to me is all about documenting my assumptions of the other systems my code needs to talk to. That way, when the integration tests fails, I can match the failure to my assumptions and know how I need to change my code. Also, unit tests are usually the only way I can tests some error states that could come from the other system if the other system doesn't give me a way to simulate that error state.

  • @Saru-Dono
    @Saru-Dono Місяць тому +6

    If it's 10-20 seconds, I don't care. I'll happily watch it to support the channel

  • @dyto2287
    @dyto2287 Місяць тому +21

    Mocks are for unit tests to test specific scenarios on small chunk of code. For integration tests you should use testcontainers not mocks. Usually you would use both for different things. Like testing storage implementation with testcontainer and testing service with mock of your storage.

  • @zyriab5797
    @zyriab5797 Місяць тому +2

    I appreciate you making these videos and not only streaming as I don't have time to watch streams. Also the feel is different than in clips.
    So thanks!
    Also, I'm cool with the ads, I think you're a man of integrity :)

  • @teej_dv
    @teej_dv Місяць тому +5

    should probably do an ad read for a really cool podcast, called Top Shelf

  • @Jason-xw2md
    @Jason-xw2md Місяць тому

    Love this format, the past few videos on this channel have been super insightful and gotten me to think pretty deeply about the topics you've covered. Also super OK with ads.

  • @harambeexpress
    @harambeexpress Місяць тому +1

    10 second ad reads sound fine. I have some faith you'll do it right.

  • @othaviorubim5180
    @othaviorubim5180 Місяць тому

    Please, continue to do this kind of videos, i love to learn and open my mind with you everyday. Good stuff.

  • @abpdev
    @abpdev Місяць тому +26

    Mhhh. Unit testing? Mock.
    Integration tests, do not mock.
    A pull request or commit should have unit test.
    I think that’s where mocking is the most useful for me. At the end of the day, you need to throw your product out in the wild in connect it with every service, do it immediately or later. It’s all up to you.

    • @jonathan2847
      @jonathan2847 Місяць тому +2

      Unit test libraries.
      Integration test binaries.

    • @youtubeenjoyer1743
      @youtubeenjoyer1743 Місяць тому +1

      So you end up with thousands of so-called unit tests that test themselves, and now your program is impossible to refactor without also rewriting thousands of lines of tests just to conform to the refactored code structure.
      Unit tests are dead code. Write integration tests instead.

    • @MrCatgroove
      @MrCatgroove Місяць тому +1

      this is a regarded rule lol

    • @jonathan2847
      @jonathan2847 Місяць тому

      @@MrCatgroove Great artists learn the rules, then break them. This is the curve meme. Dumb people don't write unit tests, mediocre people write unit tests, smart people don't write unit tests.

    • @MrCatgroove
      @MrCatgroove Місяць тому

      @@jonathan2847 For sure. This is true for everything in life. Novices and Pros do a lot of the same things, but for wildly different reasons lol. It's like learning to paint like a child, like Picasso said.

  • @jay_morelli
    @jay_morelli Місяць тому +2

    Hey prime, thanks for the video! I am 100% with you here 😄 Also, for the ads, please do! You are NOT the person of selling something you don't believe in, so I would definitely be interested in find out more cool stuff (that is what ads are for, right?)

  • @VanosTurbo
    @VanosTurbo Місяць тому +9

    I like mocking but if its to excessive its usually a indication of bad software design.

  • @Jak132619
    @Jak132619 Місяць тому

    For testing app paths with database connections I've found Docker to be a great tool to simulate databases. Set up a postgresql docker image, create some scripts to create tables and insert mock data, then swap to the database image when testing with a config option. It means you're writing a lot less code and spending a lot less time setting up mocks for your test files

  • @Jason-yr6fy
    @Jason-yr6fy Місяць тому

    absolutely, feel free to add some ads. You are great, man! Thanks for the video

  • @arthurlodbrock2549
    @arthurlodbrock2549 Місяць тому +4

    Go, PHP, Mocks… What’s next? Ruby?

  • @lengors7327
    @lengors7327 Місяць тому +3

    The usage of mocks in tests, the degree of acceptance and the degree of strength behind the reasoninh to use them, depends on the type of test, imo.
    For unit tests, mocks can (and probably should) be used and you don't need a very strong reason to do so. Their usage should be easily acceptable, as unit tests test if the code behaves as you expect it to in regards to the assumptions you make about the world.
    For integration and e2e tests, however, the degree of acceptance for the usage of mocks should be much lower, and only be used in very specific situations (i.e. have a strong reason to do so, larger for e2e tests).

    • @aboutfoss
      @aboutfoss 28 днів тому +1

      I agree! Mocks are good and preferred for unit testing.
      As you mention, it seems that two types of testing are being conflated or forced into a single test. Unit tests are meant to test code, while System testing is meant for end-to-end testing.
      Mocks simulate how code handles messages/responses outside of its scope. In this case, connecting to a db as part of the test adds complexity without improving the test.
      Imagine how complicated unit testing would be for distributed systems such as Pulsar, Kafka, or Cassandra if every system had to be online for unit tests. Every developer would have to be able to compile and run the entire application for every unit test.

  • @SaintMyles
    @SaintMyles Місяць тому +1

    Totally fine with the quick ad reads. do what you gotta do

  • @cag1
    @cag1 Місяць тому

    cool new format! 10 mins, focused, calm.

  • @einargs
    @einargs Місяць тому

    I built a testing tool for our ios app that ran a local http server and redirected all of our requests to that instead of the actual server. Then the http server could be told to return a specific JSON response for each test.

  • @keyboard_g
    @keyboard_g Місяць тому +1

    Prime's Vim theme is all different shades of purple.

    • @TheVimeagen
      @TheVimeagen  Місяць тому +1

      i have a specific theme for zig vs other languages for streaming purposes

    • @_start
      @_start Місяць тому

      @@TheVimeagen zig deez nutz

  • @streamcyper
    @streamcyper Місяць тому

    In a project I've been working on, I made a dummy database handler, that instead of using a database it uses slices and maps for the data. And it has been working great, because in the constructed world I have perfect control over what everything does, I of course use it in combination with end to end tests, but instead of spinning up a full database when I just need to give inputs and outputs to the application, I know what the input should be and I know what I want in return.
    With that I can easily check that my application work as intended, since I am programing against a defined interface, and once that breaks I know something is wrong. This works because when I made the dummy I did make assumptions on how the world works, and made something that worked with my assumption. I then of course learned that I was very wrong, but that also meant that what I was doing in my application was wrong. So I had to fix my assumption and now both the dummy and the real database works as intended. It will of course break, but that also means that I have been walking away from the original goal and I need to find out why, and either fix it by going back or redefine my goal.
    But yeah nothing can replace end to end tests....

    • @youtubeenjoyer1743
      @youtubeenjoyer1743 Місяць тому

      I don't see how that would work with a properly used relational database, unless your queries are no more complex than 'select * from table;'.

  • @slpwrm
    @slpwrm Місяць тому +3

    Its not hard to do similar mocks in other DBs, at work we do the same with postgres, we have a seed file that resets on each test suit, coincidentally the same seeds we use for local development. It works fantastic, I'm amazing to see actual SQL errors show up on the tests, that didn't happen to me before in the "mock everything" mindset

  • @hotscriptgg
    @hotscriptgg Місяць тому

    I use mmock btw. It's so nicely tied to actual code and it enforces to regenerate when you change the interface so it stays fresh. Highly recommend.

  • @philDL
    @philDL Місяць тому

    Great video, already use and love Turso, so I don't mind ads personnaly.

  • @stefanrares9143
    @stefanrares9143 Місяць тому

    No problem with the ads!
    I trust you not to sell out

  • @notapplicable7292
    @notapplicable7292 Місяць тому

    I program in a very different world but our maxim is if we can do it for real we do. Unfortunately this can only go so far and mocks / emulators become essential when you dont have spare hardware to facilitate dev testing.

  • @mattwiej
    @mattwiej Місяць тому

    Get that bag, wouldn't mind the ads :D

  • @ravihlb
    @ravihlb Місяць тому

    Ads are fine, your content is awesome and I trust you won't make it annoying to watch

  • @FaZeInvite17
    @FaZeInvite17 Місяць тому

    Loved the video! I don't mind about the small ads

  • @hapaise2924
    @hapaise2924 Місяць тому

    love this and i dont mind an ad but wouldnt prefer it

  • @johnyepthomi892
    @johnyepthomi892 15 днів тому

    Ads are fine with moderation. Get that paper baby.

  • @paulmurray3244
    @paulmurray3244 Місяць тому

    Go for it, be good to hear what things are catching your attention, and you should earn a dime or two

  • @zyr4c31
    @zyr4c31 Місяць тому

    ads but with primeagen excitement energy

  • @ssmith99
    @ssmith99 Місяць тому +1

    Ads for stuff you use are great

  • @jamesdeen1210
    @jamesdeen1210 Місяць тому

    Best non-ad ad

  • @tagpro77
    @tagpro77 Місяць тому

    Mock makes total sense for unit tests. It is not testing the behaviour of how a function integrates with something outside, but rather the code written in the function.
    Removing mocks and setting up the connected services/infra is integration test.
    Unit test is easy to run and good for quick iteration while developing

    • @mage3690
      @mage3690 Місяць тому

      I started really disliking that way back when I was doing silly things like building a math library without minus, divide, or multiply. Because every time I tested my stuff, I'd test it with like 1, 2, and 3, and it would return the expected answers. Then it would just explode somewhere or everywhere along the logic chain when I went to use it for anything useful. Obviously that's skill issues as much as anything else, I shouldn't have only tested the most trivial cases, but it's why I personally don't do mocks.

    • @youtubeenjoyer1743
      @youtubeenjoyer1743 Місяць тому +1

      The code that does IO and deals with IO failures is not worth unit testing; the returns are way too low for comparatively high investment. Extract the logic, and maybe do unit tests for the logic.

  • @HalfMonty11
    @HalfMonty11 Місяць тому

    Sqlite doesn't solve the mock problem, it just moves it. What if your schema changes slightly over time, or the format of fields stored, and you don't update your db test snapshot, then you are in the exact same situation where your assumptions of the world don't match with reality, your tests pass but don't work for real.
    The key imo is write good narrow interfaces, and have good narrow types and write your tests and mocks test as widely as possible within those bounds. That way you can know "my function behaves in an understandable/expected way in a variety of possible cases". Then as things change, as long as you stay within your interface / types then you know your tests are still good. If you have to change the interface or type, you know you need to revisit the test. There are two things at odds with each other. You want your code to be narrow, and limit possibilities for it to be used unexpectedly, but you want your test to be wide and test those limits. This of course is why you should only write generic code when absolutely necessary and the way you limit generic code is by only doing very small focused things in a generic way (like, idk, a custom fold on a generic iterable )

  • @Gandalf_Le_Dev
    @Gandalf_Le_Dev Місяць тому

    Can we get a video on your custom logs ? I love this kind of content, thanks prime

  • @stephenreaves3205
    @stephenreaves3205 Місяць тому +1

    Waiting for prime to find out about testcontainers

  • @explorepermaculture3864
    @explorepermaculture3864 Місяць тому

    The ads thing sounds fine.

  • @VivekYadav-ds8oz
    @VivekYadav-ds8oz Місяць тому +1

    10 seconds ad is completely fine. Due to the nature of your viewers being very tech-savvy, I wonder how many of them have SponsorBlock installed and would just skip the promotion anyways.

  • @turculaurentiu91
    @turculaurentiu91 Місяць тому

    What is even harder than setting up 50 servers, is causing 50 servers to error out in specific way so you can assert the error is handled correctly.

  • @MrSebLD
    @MrSebLD Місяць тому

    Mocks in go are best implemented with interfaces

  • @wesleycoder
    @wesleycoder Місяць тому

    Ad me up baby! Turso is great and I love to know about their new features.

  • @Peter-UK-nl6cv
    @Peter-UK-nl6cv Місяць тому +1

    Sure, for me ads are mostly annoying if it's for things I'm not interested in so I wouldn't mind turso ad reads at all.

  • @ProVrakian
    @ProVrakian Місяць тому +1

    If it means money for you, and you stand behind the product, I’m all for it. If you could maybe avoid the whiplash sensation that often comes with ad reads though, that would be nice.
    If anybody’s going to endorse good products and make the ads enjoyable I would expect it to be you.

  • @himalczyk258
    @himalczyk258 Місяць тому

    No ads for UA-cam Premium members, give em the ads!👿

  • @4bclover
    @4bclover Місяць тому

    do the ad of everything you can think can be REALLY useful.

  • @ficolas2
    @ficolas2 Місяць тому

    Go ahead with the turso ads, get the bag
    LGTM

  • @rasibn
    @rasibn Місяць тому

    Turso is good, go for it. Would like a turorial on their multi tenent db pattern in go maybe ;)

  • @moayedmahmod5283
    @moayedmahmod5283 Місяць тому

    i mock your mocks

  • @sirisaac8727
    @sirisaac8727 Місяць тому

    I mean this is unit-ish test vs integration test. I do agree with you though, I always prefer the latter approach, I don't see much value from the first iteration. I use mocks only for third party api's and such that I cannot do anything about

  • @JohnLovell-FTW
    @JohnLovell-FTW Місяць тому

    Mocks are good when you are in early development. SQUEEL LIGHT for the win.

  • @palharez
    @palharez Місяць тому

    Go ahead. I think good products must have to be shared with everyone

  • @gorlug
    @gorlug Місяць тому

    Well, if reality changes, and this might come as a shock: you need to change your mocks. You do it at the same time as you change your code that this mock is for.
    If you don't need to change your code, then you also don't have you to change your mocks. It's not like you write these mocks once and then never think about them again. They are part of your living code documentation.
    Btw on the topic of ads: I think they'd be fine here.

  • @johansmith2840
    @johansmith2840 Місяць тому

    no problem, if it helps you keep going all for it. But will they match Theo's advertisements?

  • @keyboard_g
    @keyboard_g Місяць тому

    You checking in your state of the world database into Git? If your service is large enough to require Postgres?

    • @TheVimeagen
      @TheVimeagen  Місяць тому +1

      sqlite is just a file that can be several kb big if you are storing quite a bit.
      my auto-scaling game server only needs shapes of servers to be stored and i can hydrate that back pretty easily

    • @keyboard_g
      @keyboard_g Місяць тому

      Yea that makes sense. We have a larger db and how to properly test without mocking datasets has been a mental exercise without burying the team when they just want to make a small change and run tests.

  • @Ross96D
    @Ross96D Місяць тому

    Turso ads would be ads i would watch

  • @DegenOne
    @DegenOne Місяць тому

    The adds are fine!

  • @ByteCurator
    @ByteCurator Місяць тому

    Short, quick ads that focus on pointing out that a cool thing exists are completely fine.
    The more the ad feels like a sales pitch, the more annoying it gets.
    That being said, the truth is that I wouldn't quit watching if it was over those boundaries.

  • @nefthy
    @nefthy Місяць тому

    doesn't the database file is my mock, get a bit tedious, when the database schema changes?

  • @moustafaharoun5141
    @moustafaharoun5141 Місяць тому

    Ads are fine I trust you that it would not be something useless.

  • @eugeneponomarov7429
    @eugeneponomarov7429 Місяць тому

    Keep it up! Looks good!

  • @OxyniteCasual
    @OxyniteCasual Місяць тому

    yes adds, i really like your videos and wish i could support you, so adds are great

  • @chuckleezy
    @chuckleezy Місяць тому

    does anyone know what theme he is using?

  • @brazghost
    @brazghost Місяць тому

    Timeline Summary:
    0:00-0:35: The creator initially felt that mocks were a good way to test complex systems but later realized they can cause issues.
    0:35-1:57: The creator explains how mocks are useful for testing specific functions but can give a false sense of security.
    1:57-4:13: The creator argues that using real data and real systems leads to more accurate results in testing.
    4:13-5:35: The creator compares mocks to documentation, noting both can become outdated or inaccurate over time.
    5:35-6:15: The creator emphasizes the importance of testing assumptions and warns against relying solely on mocks.
    6:15-7:57: The creator shares their approach to testing: using real data and systems, with a mocking library for specific functions.
    7:57-9:06: The creator concludes by asking for viewer feedback on seeing short ads for a database service the creator uses.
    Why does the speaker prefer real-world testing? The speaker prefers real-world testing because it provides more accurate and reliable results compared to mocks, which may lead to false confidence and could become outdated or misleading, like documentation.

    • @mohitkumar-jv2bx
      @mohitkumar-jv2bx Місяць тому

      Bro summary by some AI tool? Let us know which one?

  • @rissmau11
    @rissmau11 Місяць тому +1

    I really love your content and this new format. However I would say (as a mockist) that I would not use mocks here but the real thing. I like mocks for very simple components where call order and inner behaviors does not matter.
    Your test is too close to an integration test. It knows too much about the intricacies of the game server. Your mock does not constraint call order, which can hide bugs. Hard to say just with what we see but I change the design of GameServer so that it only expose one function that returns a server, whether it's a new one or not. I think it's not MatchMakingServer responsibility to negociate for a server. IMHO by doing this change, your whole code will become much simpler to test (and no more complicated mock with multiple functions to call for this test).

  • @andreaselfving2787
    @andreaselfving2787 Місяць тому

    I use mocks for testing non-happy path.

    • @andreaselfving2787
      @andreaselfving2787 Місяць тому

      And also, mocks must be exactly as the world is. If other function calls are made, the test MUST fail. expect is usually not a cause for failure, but asserts are

  • @smrdotgg
    @smrdotgg Місяць тому

    W ads I trust you

  • @Ducky39101
    @Ducky39101 Місяць тому +1

    I don't know what turso is but get payed if you can

  • @jannikl7
    @jannikl7 Місяць тому

    As long as you make the ads Tim Dillon style, go ahead 😅

  • @marcusrehn6915
    @marcusrehn6915 Місяць тому

    Have you considered contract testing?

  • @matiasbpg
    @matiasbpg Місяць тому

    Mocks for most unit tests means the code is too coupled. Fake data should be enough for the vast majority of the code

  • @ivanheffner2587
    @ivanheffner2587 Місяць тому

    When to mock: when you rely on external third-party services and need to test behavior around it. Mock their interface according to their published API and code to match that API.

    • @SteveKuznetsov
      @SteveKuznetsov Місяць тому +1

      I find this one hard. You could also write your functional code inside the imperative shell. Once you get the data from their API, write functional(-ish) code that operates over that data. Then, when you test, all you need is static test data.
      If you exercise the code that's calling their API, you run into the view-of-the-world divergence that Primeagen says here - you're ostensibly testing that your code reaches out to the service correctly and gets the data back correctly, but since it's all mocked out you are getting nothing in terms of test coverage and it's trivial to have an error in your mock mean that your test passes but production code is broken.

    • @natescode
      @natescode Місяць тому

      If you're mocking a lot, you're not testing anything useful.

    • @31redorange08
      @31redorange08 Місяць тому

      ​​@@natescode Look up "unit testing".

  • @Skaiiur
    @Skaiiur Місяць тому

    Ads is fine, sir

  • @spfy
    @spfy Місяць тому

    Isn't a snapshot of the database ALSO an assumption of the world? How is it any different from writing mocks? Over time, the snapshot you are using in your test is going to diverge more and more from the actual database.
    Unless you mean to take a snapshot each time you run the test? Then how can you verify the results, if you don't know what the test data actually is?

    • @TheVimeagen
      @TheVimeagen  Місяць тому +1

      this is very good point, but i would argue that the shape of the data is a verifiable item that will cause JSON parse / Table parse issues. thus will cause at the moment of using the issue whereas mocks can / will miss types of errors (what do you do if you get a 504 from a service? lots of people don't plan for this but it does happen rarely)
      so a db changes (hopefully) less often than the order in which call your service functions and their arguments or their potential return values

  • @guittoplex
    @guittoplex Місяць тому

    ever heard of test pyramid?

  • @louislynch1
    @louislynch1 Місяць тому

    don't write mocks, write fakes.

  • @kirillvoloshin2065
    @kirillvoloshin2065 Місяць тому

    oh wow, welcome to game dev, I guess :D

  • @NukeItAll
    @NukeItAll Місяць тому

    mocking is what happens when you try to test a systems sw like it is small module.
    unit testing works great when they test something small, concrete, like a policy engine, json parser, etc
    systems testing needs to be e2e testing. otherwise you are just testing mocks. when dealing with complex systems, most bugs will be in the seems - where one component does something that the other does not anticipate. mocks will not help you with that.
    systems e2e testing must be something that is thought of from day 1. if you needs your system easily e2e tested from day 1. this is not something you can (easily) bolt on later

  • @balintfazekas9696
    @balintfazekas9696 Місяць тому

    4:37 - Same thing John Carmack said about print debugging and actual debuggers: ua-cam.com/video/rhUwOBg4TyM/v-deo.htmlsi=E5YspS3S7hK-bDmm&t=277

  • @th4tAlbinoGuy
    @th4tAlbinoGuy Місяць тому

    ADS ADS ADS ADS

  • @sub-harmonik
    @sub-harmonik Місяць тому

    you can't really avoid mocking a database unless you have an environment for that specifically

  • @andrewshirley9240
    @andrewshirley9240 Місяць тому

    I understanding testing the "happy case" using integration tests. But testing the error cases is way, WAY easier with mocks. Figuring out exactly what inputs or environment states cause which specific errors, especially if it's some ephemeral error, is impossible. Mocks test the behavior that is independent of "reality," and most well-designed functions have a lot of this kind of independence. Like I don't care how the server determined port 42069 was the best port, but given that it did that, how does this unit handle that? I can test that. It can't test everything, integration tests are still vital, but mocks are great at ensuring you're able to hit all of your branches and have them reasonably smoke-screened.

    • @TheVimeagen
      @TheVimeagen  Місяць тому +1

      this is where simulation testing / tiger style stuff comes into big time play (sim testing be equal to fuzz testing)
      here is a great example:
      i have a bug that creeps up at 1 million connections added to my game servers. i would definitely have missed that during regular testing, caught on sim testing

  • @gabrielrock
    @gabrielrock Місяць тому

    turso ads are ok ads

  • @MiaChillfox
    @MiaChillfox Місяць тому +1

    I hate mocks, they are no better than a wet blanket.
    Over the last few months, I have had to deal with so many bugs that wouldn't have happened if the tests had run against a real system instead of mocks.

  • @Lado93
    @Lado93 Місяць тому

    But brah end to end testing takes ages. If you would write end to end test for everything that a develop i wouldnt do anything else. Unit test gives me abílity to quickly develop and test my solution and cover my edge cases and you cant do unit test without mocking

  • @dyershov
    @dyershov Місяць тому +2

    With real server requests, your tests may become non deterministic and tests become flaky.

  • @alanis4AL
    @alanis4AL Місяць тому

    Do ads

  • @hamm8934
    @hamm8934 Місяць тому +2

    I would be cautious about ad reads and sponsorships. Make sure you actually really use the company through and through. For example, when you promote kinesis, its clear you fully use their products, so why would anyone care? Do you use Turso this much? Are you an actual supporter of Turso?
    Obviously there are degrees of support. But people will have different threat levels to sponsorship. Look at Theo and Vercel.

  • @ishaankapoor933
    @ishaankapoor933 Місяць тому +1

    1st

  • @dj-o-byte
    @dj-o-byte Місяць тому

    just don't sound like you're reading stuff.