I was reading about the new horizons project, and for the spacecraft it seems they tested using simulation.  The mission was thought about for years before the software was made.  Then the spacecraft flew for a few years which gave ample time to simulate.  Other mission critical projects simply have a room full of people scrutinizing ever line of code.