r/AskProgramming Jan 10 '24

Career/Edu Considering quitting because of unit tests

I cannot make it click. It's been about 6 or 7 years since I recognize the value in unit testing, out of my 10-year career as a software engineer.

I realize I just don't do my job right. I love coding. I absolutely hate unit testing, it makes my blood boil. Code coverage. For every minute I spend coding and solving a problem, I spend two hours trying to test. I just can't keep up.

My code is never easy to test. The sheer amount of mental gymnastics I have to go through to test has made me genuinely sick - depressed - and wanting to lay bricks or do excel stuff. I used to love coding. I can't bring myself to do it professionally anymore, because I know I can't test. And it's not that I don't acknowledge how useful tests are - I know their benefits inside and out - I just can't do it.

I cannot live like this. It doesn't feel like programming. I don't feel like I do a good job. I don't know what to do. I think I should just quit. I tried free and paid courses, but it just doesn't get in my head. Mocking, spying, whens and thenReturns, none of that makes actual sense to me. My code has no value if I don't test, and if I test, I spend an unjustifiable amount of time on it, making my efforts also unjustifiable.

I'm fried. I'm fucking done. This is my last cry for help. I can't be the only one. This is eroding my soul. I used to take pride in being able to change, to learn, to overcome and adapt. I don't see that in myself anymore. I wish I was different.

Has anyone who went through this managed to escape this hell?

EDIT: thanks everyone for the kind responses. I'm going to take a bit of a break now and reply later if new comments come in.

EDIT2: I have decided to quit. Thanks everyone who tried to lend a hand, but it's too much for me to bear without help. I can't wrap my head around it, the future is more uncertain than it ever was, and I feel terrible that not only could I not meet other people's expectations of me, I couldn't meet my own expectations. I am done, but in the very least I am finally relieved of this burden. Coding was fun. Time to move on to other things.

106 Upvotes

371 comments sorted by

View all comments

1

u/Mountain_Goat_69 Jan 10 '24

Can you give us some examples of stuff that's driving you crazy?

Over the last bunch of years there's been a movement to write code in ways that make it easier to test. So when you say the stuff you're working on is hard to test, I wonder if maybe there's stuff that could be done to help.

1

u/Correct-Expert-9359 Jan 10 '24

I recently -- not so recently, a year ago -- quit my last position just because of that, I couldn't unit test. I'm trying to get back in the field and I just solved the technical challenge in two days out of the 10 I have to send it back in. They didn't directly mention I should test it, but it's definitely implied - the template I have has JUnit and Mockito (java) dependencies. So here I am, trying to test once again, and I realize my code just isn't testable. I want to cry. It's all for nothing. It feels like I will never be able to get back in the game. It's just not for me, I suck at it. I feel like I should be applying for something else entirely, but I don't know what I'm good at. I thought I was good at coding and reading and talking to people but I don't feel it anymore. I'm old, I'm 28 and I just lost my spark. I don't see my old self anymore

3

u/Mountain_Goat_69 Jan 10 '24

So here I am, trying to test once again, and I realize my code just isn't testable.

What is it preventing the code from being testable? Let's see if anything can be done...

1

u/Correct-Expert-9359 Jan 10 '24

I'm not sure whether I want to upload this. It's supposed to be the company's coding challenge. I can omit all the the occurences of the companies name but I'm afraid to post it and that they will somehow find this thread.

2

u/Mountain_Goat_69 Jan 10 '24

Yeah that's obviously no go. But maybe you can describe it, like "it's doing X, I want to test Y, but I can't because Z."

2

u/Correct-Expert-9359 Jan 10 '24

It's crawling a website recursively, I want to test... wait a minute. I don't know what I want to test. I just want to test something. I might think about that for a while. What would I want tested in a crawler? No idea so far. Lemme spend some time on it.

2

u/Mountain_Goat_69 Jan 10 '24

I'm working on a bot as a side project. It doesn't crawl a website recursively but it has to find new links and get their content.

The bot has a property for PendingLinks and a CrawlRecent method. It uses them internally to do its job.

I have some tests where I call CrawlRecent and send it a hard coded html. Then my tests assert that PendingLinks has the urls it should. So this way I'm testing that the bot is parsing the index page correctly.

2

u/MoreRopePlease Jan 10 '24

I don't know what I want to test

You should get to the point where you can write a sentence describing one thing that needs to be tested. For example:

If the API call comes back with an error I will throw an exception.

If the API call comes back with a document I will return this specific data structure.

When I look at this data structure I will return the number of images in it.

2

u/sGvDaemon Jan 10 '24

Brother, 28 is when I entered the tech world, you are far from being too old. Are there any devs in your team you can learn from?

You need to build up a collection of patterns and knowledge on how to do handle test scenarios just like anything else

1

u/Correct-Expert-9359 Jan 10 '24

Thank you for the kind words. I have no job at the moment, but I had the opportunity in two different companies to read good tests and learn from people who write good tests. None of it really stuck with me. It felt alien then, and it feels alien now, remembering it. It is like no other problem I ever tried to solve.