I like to use circuits.io aka TinkerCAD for this. Many other Arduino simulators are out there if you search, and new ones are being announced, even crowdfunded, all the time.
The Python based Arduino Simulator is another option, that plays well with the official IDE.Simuino simulates the Arduino Uno and Mega pins - not a pretty-looking realistic simulator, but it works.The CodeBlocks Arduino development environment includes a free Arduino simulator, still under development but functional.There are a whole slew of Arduino simulators out there, many free, and some paid products as well.