I recently started working at a startup whose code was developed under very intense business pressure. This combined with the attitude towards code needing to "work" and not code needing to be qualitative has lead to a messy codebase. One can argue that at least if the code _does_ work then it's ok, but we're dealing with many errors daily. Luckily we do have sentry and continuous deployment set-up (no CI though), so these errors can be fixed quickly when they are seen.
Needless to say, we don't have any tests.
The code is messy in most places, not all. We're working on improving the codebase, but I still feel like I'm not very well equipped to work in functions that has 10s of database queries, over 100 variables, nested if-statements, and if-statements with 5 or more checks all over the place.
I'm trying to learn testing, but under these circumstances it's still kind of difficult.
The positive side is that I do get a lot of time to read, research and learn, and I do get the freedom to try things out if they provide some form of benefit for us.
I consider myself a medior in terms of experience, this is my second job in programming.
Then I would look for chunks of code I could break out into their own functions and break it out.
Next I would write some tests for those smaller functions.
Finally I would test the new function calling the smaller functions with the tests used against the original.
Depending on the complexity of the original function, you may have to write more tests.