They can’t use real ammunition or really fire the cannons, right? Otherwise, It would be like:
“The drills were a success, sir. We sank five of our own ships!”
You don’t shoot live ammo at manned targets. When you’re doing a force-on-force exercise you just go through all the motions with the actual weapons locked out. So you pull the trigger, nothing happens, and the referees decide whether you scored a hit.
Live fire training you do against targets (drones, big floating reflectors, or derelict ships) and they are generally expected to get blown the fuck up. The US Navy even turns old fighter jets into RC planes just to shoot them down.
Most of the time, the drill will just involve everyone going through the motions of all the steps leading up to firing the weapon (find the “target”, move into range, etc.) with the actual weapons locked out so they don’t fire. Since the target could very well only exist inside the ship’s computers, the crew is basically playing a video game of their job, with all the real equipment. This is done mainly because the weapons, especially today with ships mainly being armed with missiles, are pretty expensive and get used up fast if they were expended for each drill.
There are also drills where the weapons are fired at an actual target. Back in the days of cannon armed ships, you could have one ship of the fleet tow along a target for everyone else to shoot at. Air defense missiles can be fired at drones. The US Navy also conducts what they call SINKEXs (sinking exercises) where they take a decommissioned ship, clean out the hazardous materials, then set it adrift and pummel it until it sinks. These are also more about testing the weapons and the resilience of the ship than training the crews though