Press "Enter" to skip to content

Writing unit tests for personal projects? – FunFunFunction #29


good Monday morning I am mpj and you’re

watching fun fun function today I want

to do a YouTube cover of a Korra answer

that I wrote some time ago and it’s

titled do you write unit tests for

personal projects and the answer is yes

right

your goddamn unit tests always to be

perfectly honest I am actually a little

more disciplined with writing unit tests

for my personal projects because you

know they are my babies

and also because I often have the luxury

of being the only one working on them so

I I get to structure the applications

for testability from the start I write

tests because I firmly believe that code

without tests is buggy and bad code if

I’m not writing tests I believe that I

am doing a bad job over the years I have

become more and more convinced that unit

testing and holds the same value as

things like for example version control

it’s it’s one of those things that is

just stupid not to do if you’re writing

a teeny-tiny script with only one

execution paths and it will only live

for a couple of weeks then yeah unit

tests are overkill but beyond that I

have found that it almost always saves

you time if you intend to actually spend

a couple of weeks on something or longer

then unit tests will pay off that

assumes that you are a kind of

experienced unit tester the first time

you do unit testing it’s gonna be very

slow because you know you’re bad at unit

testing you have no idea how many things

break and break in your code until you

start writing unit tests for them it’s

just ludicrous I am currently looking at

a relatively small piece of code that

I’ve written for Spotify so I can’t

unfortunately not show it to you but it

is slightly about 250 lines of code and

it has 137 test cases let me repeat that

250 lines of logic

ended up being 157 test cases and this

is not me being crazy or anything adding

a lot of unnecessary test cases I don’t

test every possible variable or anything

like that if you’re only doing manual

testing on your side project you’re

probably checking 3 or 4 cases every

time you you commit maybe if you really

disciplined a lot more discipline than I

am you’re doing 10 even if you really

disciplined you are simply not gonna

test everything using just manual

testing it’s not realistic the way I see

it when you’re writing code in an

existing code base you’re going to break

a lot of things that used to work before

your change and a lot of those errors

are going to be subtle and if all you

have is a manual test suite and you

don’t have an automated test suite

checking all those for you you are

probably gonna miss them I know that

unit testing often feels frustrating

when you are developing a new project

because it feels like they’re slowing

you down and it doesn’t feel like the

code is all that complex anyway but you

have to remember that after only a few

weeks of development your time will have

shifted you are now not spending most of

your time writing new code you are

spending most of your time making

changes in existing code and making

changes in existing code can be done

many times faster like 10 times faster

if you have a good unit test suite for

that piece of code and that is why unit

tests save so much time even on pretty

small personal projects I am MP J and

this was an episode of fun fun function

I release new episodes every Monday

morning so make sure that you subscribe

so that you don’t

out on the next one if you don’t want to

wait until Monday you can check out some

of the older episodes here pick one of

them until next Monday morning stay curious

Please follow and like us: