Sadly, (almost) nothing is free in the world of PLCs.
The S7-PLCSIM software is not so expensive, and worth every penny to my opinion.
When you have a PLC simulator, like S7-PLCSIM, then you can indeed test your programs without connection to a real PLC.
A trick to get a "free" PLC to test on: If you have a project under way, then purchase the CPU up front and you can use it for testing until it has to be installed in the control system it is destined for.