Just to provide an actual, researched, answer on here.
TestDisk is next to useless for Mac, as is PhotoRec.
They can't read APFS at all, so for any OS newer than High Sierra 10.12 it is totally pointless to install, unless the drive you are trying to recover from is FAT/ExFAT, which precludes any boot drive; and you shouldn't be using any FAT structure on Mac unless you absolutely need cross-platform portability. Even then it's better to use HFS & install a comparable reader utility on your other platform. FAT cannot store unix permissions or ACLs & will actually break some of the Mac's data structures such as Photos or iMovie libraries and Logic Pro Project files.
Installing software on the drive you are trying to recover is counter-productive. You may be overwriting the very data you are trying to recover.
Being already prepared by always having a known-good external boot source with rescue utilities is always better than panicking afterwards.
Having a tested, working backup solution is better still.
If you have none of the above, then copying the drive using dd to another disk first, before installing any new software, would be safer.