Can your settlements actually get attacked?
Solution 1:
Yes - I've had multiple instances where my turrets have opened fire on Deathclaws and other wasteland wildlife, the moment one of your defences start attacking (whether that be a settler shooting something or a turret opening fire). The attacks will kill settlers and destroy (reduce durability to zero) defensive structures and crops. You'll get the opportunity to fix any damaged structures or crops but if settlers die, that's final.
This means you'll want to ensure the approaches your settlements are well guarded and that you should position your defences for optimal coverage. However, I have noticed that in some instances when you don't turn up to a help a settlement that is under attack an unexplainable amount of damage will occur to your defences anyway... they do seem to help anyway and it might just be a coverage thing, and they're certainly helpful if you do respond to the settlement's call for help.
One of the earlier tooltips in the game indicate that your chance to get attacked is based on a your resource generation in comparison to your defence rating, and that you should keep your defence rating equal or better than your combined resource generation.
Solution 2:
I was wondering this, as I've gone for the build fort knox method. Placed defense posts around and turrets and spot lights and sirens etc. First time after 4 days of playing I'm breaking down components and the siren went off. Had about 15 ghouls trying to attack one side of the settlement. Luckily I had 9 ppl plus me and the turrets. It didn't take long to deal with, but yes it does happen