If I have a pain in one of my testicles, what kind of doctor should I go to to have it examined, and at what urgency?

Primary or urologist. You can see your primary care doctor for an evaluation and if they are unable to diagnose the problem a urologist should be able to. Some urologists will require a referral from your primary care physician.
An ER doc, Urgent! An emergency physician is equipped to handle emergent conditions of the testicles, including testicular torsion, which is a true emergency, and they can immediately have you evaluated by a urologist who can correct the problem surgically if need be. The urologist can also make other recommendations or treatments to alleviate your pain if a non-surgical cause is found.