Ideally you should use the visudo command to manage sudo users. visudo checks the file syntax before actually overwriting the sudoers file. This command should be ran as root to avoid losing sudo access in the event of a failure.
It is required that you specify which file you are attempting to edit with the -f argument:
# visudo -f /etc/sudoers.d/test
As for recovering sudo on the box with a malformed sudo config. The process will depend on which platform (AWS, GCP, baremetal, qemu etc) you are using. On AWS I was able to stop my instance, detach the ebs volume, attach this volume to another host, mount the root partition, and delete the /etc/sudoers.d/dummy file, then reattach this volume to my instance.
Cheers,
Kyle Brown