Perhaps started by people trying to be less vulgar than using "as fuck" or "as shit", but still wanting to use a dirty word.
The resulting phrase doesn't have to have anything to do with testicles or their qualities; it's almost better when it's very un-ball-like, because it makes other people stop and think how your phrase doesn't make sense.
Dude, your mom is hot as balls.
I was sick as balls last night.
It's cold as balls out here!
It's cold as balls are not!