Update to my last post:
If you are self-pleasuring, but NOT having an orgasm, this can cause temporary pain until your body returns to its unaroused state.
You don't mention whether you are, in fact, having orgasms during self-pleasuring, so I thought I'd include this on the change that you aren't.
Hello.
Without further details, I can't really give you any information. You don't give your age, so I have no idea whether you're just starting puberty or whether you're through it.
Sometimes during puberty, the testicles can be painful during growth spurts. This usually ends once you're post-pubescent.
During sexual excitement, the testicles rise up closer to the body, and after orgasm, they descend. Sometimes this creates some discomfort.
Another possibility is that you have an infection of some sort in the epididymis (the part of your testicle that produces sperm).
And finally, you may have been exposed to an STD such as chlamydia through outside sources. Some STD's can cause testicular pain.
If you continue to feel more than just mild discomfort, you should see a urologist for an exam and tests to find out what's going on. Dr. J