I know testifying is scary, hopefully you have some support through it. If there is a victim support program in your area, talk to your worker.
There will be other people in the courtroom and your ex will not be able to approach you or talk to you at court. If he is not currently in jail, speak to someone involved in your case (victim support worker, detective, lawyer) about your fears. Maybe they can arrange to have extra support and/or security for you. At least a safe space to wait outside the courtroom when you are not testifying. And if you can, try to bring a trusted friend or family member with you for support.
Best of luck and sending you hugs.