First of all, it sounds like you're being really chill about this and sending him the right message, that by working on issues that come up we can improve them, and that the grades are an indicator of something not working in how he is studying or test-taking, not something wrong with him, his intelligence, anything like that. Props! With that, a couple approaches/strategies that came to mind that I might consider trying in your shoes:
Can you do some practice tests with him (timed) in a busy public place like a library or coffee shop? You obviously can't replicate the exact test situation but it would have some of the same elements like distractions, etc. so you can observe and diagnose what's going on. If it turns out or you suspect the thing messing with him is pressure rather than those things, maybe put chores or allowance on the line? (I'm thinking as both carrot and stick...give him something to win but also something to lose, but not in a punitive way...more like gambling?)
The other thing that comes to mind is: how does he study? I've always hated tests with a time crunch element, but I also eventually realized that being able to do something fast tends to be an indicator of knowing the topic/process well. It could be the homework is not enough problems to actually be enough practice for him for the test; if he's studying by reviewing the concepts/reading the book that may not be helping him, and doing a few more problems might.
Also, I'm no expert at this, but I've been reading a lot about meditation lately. Not in a woo-woo way, but people report that sitting even 3-5 minutes trying to focus on your breath every day can help you train yourself to bring your brain back from distracting thoughts and keep focus on a task at hand. I haven't been a regular at it but I've turned to it when my anxiety acts up and have noticed it helping sometimes.
This randomly just reminded me of one more thing: sleep!! My brain is totally scattered if I don't get enough, and I make more careless mistakes in my work, or go slow. Middle school is a weird time for sleep, but anything you can do to ensure he gets enough good sleep 2 nights before a test (motivate encourage, bribe, force, etc) will probably help. To sweeten the deal, give him a chocolate bar to have before the test; my mom always said it was good for focus and gave us one before SATs and the like ;)
PS disclaimer: Not a parent, but I've tutored, worked with 12-17yo in summer camps, and have a general interest in education. And have done a LOT of school.