Sometimes, sometimes not. You can have a full engineering model, a bench model (same h/w componants, but layed out on a bench), a simulation running using the same physical processor, or a complete software simulation. And probably other variations.
Modifing the on-board spacecraft software is often done to cope with hardware that's either failing, or behaving differently than expected. It's not just s/w bug fixing. That kind of fix might be easier to test in a software simulation, were you have full control over the virtual hardware, and you can make it behave how you want.