Press "Enter" to skip to content

How to know if your tests are correct? – Twitch stream highlight


when you do TDD how do you make sure

that your test all right do you write

the test for your test

well that depends

let’s say that you have if you if you’re

doing TDD and you’re writing like an or

calculator or something and you say to

the like you write a test that checks

that if you put in 2 plus 4 does that

return for that you don’t need to verify

that that test is right I mean that that

is just an example so to speak that is

what the the report was what the test

does it’s it’s very clear you can must

like ocularly see that the test is

correct however let’s say that you

instead have a piece of code that calls

another API let’s say that you have a

function I did this in one of the other

in the unit testing series you have a is

a code that fetches the tax rate from an

external service given a country so

given that you pass in a country to this

function yet it passes it does a fetch

request to certain API with some certain

parameters and given some jason it

parses that jason and then it extracts

some piece of information that could

back from that thing then in that case

then your unit test is going to you just

have a mock for that it’s not gonna

actually go away and fetch a network

request every time you run the test

because that would be insane like those

tests would be really slow so you’re

you’re mocking that and that is tricky

because you might make a

stake in how you set up the mock so even

if you test this green and oh this does

the correct correct fake request fake

side effect the side effect might

actually not be the one you want so in

that case you will actually have to

manually verify that the the effect that

your once you have test green you have

to actually take the unit test and run

that and inspect the results manually

and like okay yes it’s test is correct

and only then do you actually save and

commit the test so whenever you have

side effects with unknown forms then you

will have to manually verify every unit test you write once

Please follow and like us: