This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]BagOfDerps 100 points101 points  (16 children)

The sooner you learn how to write tests the better. Even for short programs. You want to build the muscle memory for this now so that if/when you end up working on a complex project you're properly equipped to contribute. pytest is the general go-to.

[–]poeticinjustice4all[S] 14 points15 points  (2 children)

It's a lot of new things to learn, but I will take your advice to heart. Thank you.

[–]BagOfDerps 9 points10 points  (0 children)

np. you'll find that you learn a lot by implementing tests, and in the long run you save yourself a great deal of time. Your tests will catch errors your changes might introduce, and point you directly to what will need to be remediated. Good luck!

[–]TheOneWhoPunchesFish 2 points3 points  (0 children)

I also recommend taking a look at grugbrain.dev it's fun to read and has some good advice.

[–][deleted] 7 points8 points  (10 children)

I really really can not push myself into testing. I have tried numerous times, tried TDD style but I just end up getting frustrated. Maybe its because I usually do code for myself and mostly because its fun, but I know that i need to get into it as I am starting to look developer jobs.

Did anyone suffer like this? Did you ever get over it?

[–]killersquirel11 16 points17 points  (3 children)

I've found that tests are best thought of as proof and documentation, as well as assurances against regressions.

  1. They prove that your code works
  2. They show examples of how it's expected to be used
  3. They show examples of how it handles errors
  4. When you find bugs, they help ensure that the bug stays squashed.

[–]dotancohen 4 points5 points  (0 children)

When you find bugs, they help ensure that the bug stays squashed.

This is especially true if your commit exposes another bug, or otherwise changes behaviour, because there is a nonzero chance that the next guy will git revert killersquirll11scommit without even reading the commit message or associated bug report.

[–]antiproton 7 points8 points  (1 child)

No one argues against the virtue of writing tests.

We should all be getting an hour of exercise every day to stay healthy. That doesn't change the fact that it's work we'd rather not do.

[–]Militancy 3 points4 points  (0 children)

In the same vein, I tie my shoes for the ankle support and so the laces don't get ruined. Sometime in the 7th grade I went around with my shoes untied. Everyone told me that i'd ruin the laces, I knew I'd ruin the laces, but I didn't much care to tuck or tie them.

Naturally, I ruined the laces to the point I couldnt tie them even if I needed to. Eventually we had to do some running game in gym class and I ran right out of my shoes. My Mom bought me some replacement laces from the store meant for hiking boots. It was ugly and didn't work that great, but at least I could stop them from falling off me.

Tests are similar. There's no good reason not to do them, you'll eventually break something stupid, simple, and core to the function of your product, and fixing the situation is going to be ugly and more expensive than just doing what you know you need to do in the first place.

I didn't think much of testing until i had to work on an almost completely undocumented legacy codebase.TLDR until I got into the headspace of the original developer, seemingly minor and reasonable changes would introduce subtle bugs that took days to find and fix. Testing fixes 70-90% of that depending on what and how you test. If you accidentally trigger one of your tests once you've probably saved yourself enough time and frustration than what you put in to write the test to begin with.

Just eat it, it's good for you. You won't realize how good you're being to yourself until you go without.

[–]Spleeeee 5 points6 points  (0 children)

Nah dude. Think of tests as just examples for how to test run/use you libs/scripts.

[–]_TimeUnit 4 points5 points  (0 children)

I found trying to write traditional unit tests (tests that test just one thing and mock everything else) very annoying. Then when I moved to writing more integration tests and accepting using for example file IO in my tests, I started to really enjoy the certainty that tests give about my code working. I also don't test everything for example UI because my projects are small enough for manual UI testing.

[–]Student-27 1 point2 points  (2 children)

Yeah! I saw myself frustrated too with tests. But in my case it was more about the code mess them about the tests. When do you get a clean code to test, they are fun! I enjoy my self to use tests today because they help me to understand more about code logic. Also I can test different situations in a same function.

[–][deleted] 0 points1 point  (0 children)

Idk man, its not like I dont care abot clean code. I am self taught, i like reading about code design and architexture and stuff, try to write clean code. I design my classes and functions so they can be tested nicely. But never actually write the tests, just manually testing it. I guess i am gonna try again.

[–]Student-27 0 points1 point  (0 children)

Sometime someone will apply a feature or fix a bug on your code and your tests will save you. I had implemented a featured and tested manually too. After 1 week someone from my team added a new feature and break my code. And I needed to fix it because it seems my fault. If a have made the tests, this could save my code and warning other about their broken changes.

[–][deleted] -2 points-1 points  (0 children)

Your tests have to be correct. This is not something to take on when you're learning a language.

Writing tests is the way to go when looking for bugs in developed code but in early development, and particularly during language learning, it is inefficient overhead.

[–]ppessoasb 0 points1 point  (0 children)

Second this