Mocking in Rust

preview_player
Показать описание
Today I am going over the basics of mocking in Rust. Mocking helps us write unit tests without side effects such as database queries, network calls, or file system manipulation.
Рекомендации по теме
Комментарии
Автор

Mocking is what the borrow checker does to me still. I’m about half the way through the book video playlist. Thanks so much for doing them.

daque
Автор

This is great! It'd be cool to have a video going over how to test a larger rust codebase - what should be unit tests, what should be integration tests etc. and how to split it up.

azayakabaka
Автор

Important thing is that this crate can also do struct mocking, not only traits. That's very useful

arjentix
Автор

Bro you can't understand how much I spend trying to mock third API in rust. Your video is what I needed to learn more about mocking concept. Thanks bro

niyongaboeric
Автор

Yes! More please! Your explanations are a good supplement while working through the rust book. Thank you for all the work you put into making these videos.

PaulHosler
Автор

Rust has really a lot of powerful features. That's amazing.

martinfilteau
Автор

Thanks! Haven’t really tried rust mock. This video completes all the basics.

changtimwu
Автор

Yeah great, more test-content please.
Question: Could one use a generic parameter instead of a Box<dyn Database>?

teevorian
Автор

Just started looking into mocking unit tests in rust and have seen a few of your vids before hope its a good one

ianknowles
Автор

Just in time. I'm creating the first Rust app and that's what I actually needed next :). I would definitely be interested in more advanced mocking patterns and also dependency management. For example in this video you pass dependency as an argument of the function. But coming from the web, there are more patterns like dependency injection or factory functions (I don't remember the correct name for this pattern) where one function takes deps and returns another function that has deps baked in. Then when testing you just call the factory function with the mocked deps. Is something like that possible in Rust?

lukejagodzinski
Автор

Mocking is also a really important skill, if you ever encounter a Go developer.

SEOTADEO
Автор

Hey, good video. Question: What if the underlying API implementor is not exposed to the fn arguments?

debuti
Автор

Great video! I'd like to see this applied to sqlx.

ZnMgkbvprb
Автор

This works great if the trait is in the same crate. How do you write unit tests when the parameter trait is in a different crate?

saikatdas
Автор

Hi could you Please Explain std::marker::PhantomData, & why we need this ??

RAHUDAS
Автор

So it seems that the expectations on the mocked object are just setting up the expectations and not actually checking them and the mocked object probably implements Drop trait and in that it checks all the expectations when it goes out of scope.

ankur-dhama
Автор

This looks like it will only work for boxed objects. What if you don't want to store your object on the heap?

jkjensen
Автор

How can I mock a method or an associated function from an external struct, which is being used inside of my struct method? I tried `mockall`, but it seems not promising. :(

don_t_ask_anything
Автор

These videos that err on the practical side of software development are great. You can basically spam a video on every half-useful library crate out there and I won't complain 😅
A common oversight by more experienced developers when they teach is the tools that they've come to take for granted, while their students waste tons of time remaking what's already been implemented/automated. I've been on both sides of the coin so I know this firsthand, and I'm sure you do too.

scheimong
Автор

How do you really apply this?

Say i have a function which calls a rest api for some json data and processes the data. I’m using reqwest to get the json data, but in test i want reqwest.get to be mocked and return a fake response body, and that fake body will be used further in the function and get processed.

Phdz