Why does a doctor hold your testicles while you cough?

The reason that a doctor performs this examination is to check for a Varicocele. A Varicocele is a swollen varicose vein that may be in the scrotum and is usually on the left side. The physician checks for a hernia, which is when a portion of the intestine decends into the pubic area, and possibly into the testes. When you cough, your abdomen expands/contracts, therefore moving the intestine if it has descended. The doctor can feel this, and determine whether or not you have a hernia. This question has been answered by a healthcare professional, not an M.D.