Thoughts About Unit Testing | Prime Reacts

  • Опубликовано: 4 месяца назад

    ThePrimeTimeThePrimeTime
    подписчиков: 248 тыс.

    Recorded live on twitch, GET IN
    / theprimeagen
    Article: blog.boot.dev/clean-code/writ...
    Author: Lane Wagner - / bootdotdev
    support me by checking out: boot.dev/
    MY MAIN YT CHANNEL: Has well edited engineering videos
    / theprimeagen
    Discord
    / discord
    Have something for me to read or react to?: / theprimeagenreact

@tiskahar9738 +394
@tiskahar9738

the irony of listening to this while actively writing mocks and excessively unit testing

@pdwarnes +170
@pdwarnes

I find a lot of mocking comes from arbitrary code coverage percentages (80%-100% unit test code coverage). Also seen with: "unit test confirms exact log output", and "unit test getter/setter/properties".

@AJMansfield1 +41
@AJMansfield1

For testing library-type code (e.g. data structures) in dynamic languages, mocks can be useful for verifying that your fancy data structure isn't accidentally doing something untoward with the objects you're entrusting to it -- you can verify that only functions that are part of the interface that algorithm requires are called, and that things that are part of only

@bobbycrosby9765 +45
@bobbycrosby9765

These blogs always pick an easy example. Most validation also requires examining the database. A common one would be, in this scenario, a requirement where user email address needs to be unique.

@kaanatakan +48
@kaanatakan

There is a valid use case for mocked APIs: One time I was writing a shipment tracking service and it would connect to the API's of various shipping providers and check the status of packages and trigger notifications to users devices. While some of the shipping companies provided testing servers they didn't update the package status since there was no actual package and no real delivery process. So I couldn't use the actual API even if I wanted to. Instead I created a series of responses and stored them in a bunch of files. Then I served these files iteratively. A big benefit is that your test can go real fast without the network latency. But you have to maintain the mocked responses which is kind of a bummer.

@misskalkuliert3976 +4
@misskalkuliert3976

Hello Prime,

@fennecbesixdouze1794 +9
@fennecbesixdouze1794

I love Go's named returns. Keep in mind you absolutely don't have to use them naked. They are extremely useful as quick bits of documentation if you have helpful names for the return variables, especially if you are returning more than one variable of the same type.

@drknoba +17
@drknoba

100% agree! Mocks are a great way to fk up your test suite. Where i work, my boss mocked all his internals and taught the rest of the engineering team to do it. I never gave in. After he left i was finally able to convince the team to stop doing it. Your test should describe a narrative on how it behaves, not how it’s implemented.

@kairo1502 +67
@kairo1502

I highly recommend reading "Unit Testing Principles, Practices, and Patterns" by Vladimir Khorikov. It's probably one of the best software design books.

@theherk +4
@theherk

Many great points from you, the article, and many comments, but I don’t think mocks are a problem

@remrevo3944
@remrevo3944

I would say there is one case where mocking is both trivial and definitely should be done: In Rust when parsing messages from some kind of data stream, when it is written correctly, it is easy to just get the test data and put it into a Cursor . That way you can just unit test the logic without having to do anything complicated.

@shanebenning +54
@shanebenning

“… fixed TypeScript’s biggest problem” is the summoning ritual for Matt

@PhillipDressen +26
@PhillipDressen

The first time I heard about JavaScript on the back end, I laughed thinking it *was a joke*... I don't regret how hard I laughed

@moraigna66 +23
@moraigna66

I was taught mocking in school, it made a lot of sense to me. You want to decouple the code in tests. If module A depends on module B, you unit test B, then mock B for A's unit tests. That way, if a dummy breaks B, only B's tests fail and it's way easier to find the bug than if all tests fail together.

@alexaneals8194 +1
@alexaneals8194

The one area I like to use mocks is to put the code in an unexpected state and see if handles the error and that it gives a reasonable error message. If the program is logging errors then I will mock out the logger to catch the error directly and compare it to what is expected rather than actually write the error to log. The other area is when I have to fix legacy code and I need to mock out the stuff that is irrelevant or that is creating expensive connections. Sometimes you can break the code out into a separate function and not have to mock it, but I have run into cases where that's not possible without a major refactoring of the code.

@Optable +1
@Optable

Beeceptor has been a heavensend for mocking, debugging endpoints and timeout problems, testing adjustments pre/post production, CORS support, Customized Dynamic responses, Mock serving for OAS Specs. It's fantastic

@EbonySeraphim +1
@EbonySeraphim

This absolutely 👏🏿👏🏿👏🏿 As soon as I learned about mocks, I intuitively thought something was off about them. I came to see limited value due to the use of a very difficult coding framework (AWS SWF’s Flow Framework), but outside of that I saw a bunch of devs pretend that they needed to test that database and other remote call parameters were set exactly. If anything necessarily changed with the API functionally the same, you broke the test for sure because it was validating the internal procedure not the behavior.

@kezzu5849 +5
@kezzu5849

Shout out to the author for using "Super easy, barely an inconvenience" 😂 Pitch Meeting has reached the far reaches of the internet 🙏🏿

@LEGnewTube +6
@LEGnewTube

I think mocks are useful when your functions make calls to third party things. Like for example if you have a route that does some stuff and makes a call to an email client. You have to mock the email client response because you shouldn’t actually be calling a third party service in your unit tests.

@NilMNV +2
@NilMNV

The main problem is that people just don't realise what exactly they can test with different kinds of tests.

Далее

When To Unit, E2E, And Integration Test

14:58

When To Unit, E2E, And Integration Test

ThePrimeTime

Просмотров 63 тыс.

Clean Code is SLOW But REQUIRED? | Prime Reacts

28:22

Clean Code is SLOW But REQUIRED? | Prime Reacts

ThePrimeTime

Просмотров 149 тыс.

ВЫГНАЛИ ИЗ ДОМА #shorts

00:40

ВЫГНАЛИ ИЗ ДОМА #shorts

Паша Осадчий

Просмотров 881 тыс.

Why Would Anyone Hate TDD? | Prime Reacts

46:52

Why Would Anyone Hate TDD? | Prime Reacts

ThePrimeTime

Просмотров 96 тыс.

How Senior Programmers ACTUALLY Write Code

13:37

How Senior Programmers ACTUALLY Write Code

Healthy Software Developer

Просмотров 952 тыс.

Why I Don’t Unit Test

8:25

Why I Don’t Unit Test

Theo - t3․gg

Просмотров 79 тыс.

Why I Quit Netflix

7:11

Why I Quit Netflix

ThePrimeagen

Просмотров 383 тыс.

Dependency Injection | Prime Reacts

28:34

Dependency Injection | Prime Reacts

ThePrimeTime

Просмотров 175 тыс.

If I could give advice to myself when starting as a software engineer

5:56

Why You Should AVOID Linked Lists

14:12

Why You Should AVOID Linked Lists

ThePrimeTime

Просмотров 190 тыс.

Dev Caught Catfishing EVERYONE

31:27

Dev Caught Catfishing EVERYONE

ThePrimeTime

Просмотров 74 тыс.

"Clean" Code, Horrible Performance

22:41

"Clean" Code, Horrible Performance

Molly Rocket

Просмотров 742 тыс.

ВЫГНАЛИ ИЗ ДОМА #shorts

00:40

ВЫГНАЛИ ИЗ ДОМА #shorts

Паша Осадчий

Просмотров 881 тыс.