Testing is a good way to ensure that your program won't have UAF under most normal circumstances. But when it comes to security it's adversarial - your program will get pushed into parts of the state space that were never seen during testing.
Things like browsers and operating systems are all heavily tested and fuzzed using tools like asan. They still have security issues from UAF.