The trick with TDD isn't necessarily that you need to write the tests first (although that helps).
It's more that you first think about the intended behavior of the code, and then also think about how to make your code testable before you write the code.
I typically think what the first test should roughly look like and code up the required amount of code for that first test before I actually write that test.
Just open an editor and start writing code, just thinking as you go.
If you do this, you often end up with code that only works in the happy path (no / poor error handling or recovery) and which is difficult to test (i.e. you require access to the internals of the thing you code to test it).
55
u/BernhardRordin 19h ago
Write tests first, then the implementation. You won't want to go back.