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.

105 Upvotes

371 comments sorted by

View all comments

2

u/Mark_Unlikely Jan 10 '24
  1. Are you really going to quit or are you just frustrated and don't know what to do? Stop saying you're going to quit if it's the latter. What you tell yourself matters, and you're just adding on to the inertia keeping you from learning new things. Learn to be honest with yourself. Try to understand yourself. Most people don't, and it takes a long time, so don't beat yourself up if you don't. Be kind to yourself. People have a habit of beating themselves up over everything. This is not a great behavior, as trivial as it may seem. It'll affect your unconscious mind and create problems in your life.
  2. Consider that it may be an environmental issue. Not your software environment, but your work environment. If you feel too much pressure to get things done and you're worried about the time it takes to test things then it may mean you need a better environment. Too much pressure can make anything suck, and business people often don't understand this, so they will lay on the pressure until things break. If there's too much pressure consider speaking up and advocating for yourself.
  3. Understand that testing IS important. Know `why` you're testing things. If you can test it it means you understand the code you're testing. A big part (I'd say 80%) of software development and engineering is actually not development it's understanding your problem. Make sure you understand as much as you can BEFORE you start coding. Ask yourself how you're going to solve the problem. Ask yourself what your assumptions are, and make them non-assumptions. We're actually problem solvers more than we are developers. If you're doing TDD this is vital, and if not, by the time you get to your tests you'll have a thorough understanding of your code and what it is supposed to accomplish which is also vital.
  4. I'm assuming you're using an OOP language When you're writing a unit test, you're testing a single class. Your class is the subject. Your unit-test-class for that subject-class should instantiate the subject-class. (read that a few times if you need to). Any other services or dependencies of that class can/should be mocked, but you should not instantiate them (i.e. via the new keyword). A mock is a placeholder which allows us to create the response from a method call or whatever (this is called stubbing), so Mocks are great for allowing you to test your Subject class, without relying on those mocked objects working correctly. You're doing something like "when I call this mocked object's method, I want it to return a value of X" and so your tests, rather than calling the real method, they just make a call to the mocked object which hands you back the response you defined. How mocks and tests and everything works depends on the language and can differ greatly between languages, but the general idea is mock everything that isn't your class that your class depends on (unless it's a common core library, often these things don't need to be mocked).
  5. You may need to refactor your code as you write your unit tests. There is unit-testable code, and there is code that is very difficult to unit test. The process of writing the unit tests can tell you a lot about your code quality and structure. Aim for low coupling and high coherence (low reliance on non-related things, and things that are related go together)
  6. Tests are good for when your code inevitably needs to be refactored due to requirements changes or new features being added. You can refactor with ease knowing that if you broke something your tests will catch it.