Usually ahead of time, or when they show some sign of failure. I can't remember many batteries just flat out being completely dead. I can usually hear a sign of weakness of slower starting ahead of time.
I replaced a leaking battery on my Jeep 2 years ago, still started it just fine. But I take it out to the middle of the desert off-roading and don't want a failure. A few months ago the Genesis still started but sometimes had a little hesitation to start, had it tested and it was at like 1/2 the CCA. That one is an ouch, $250 battery.