The word 'testify' derived from a time when men were required to swear on their testicles.
The Latin word for a witness was testis, which derives from an Indo-European word for the number three. That was because the Romans regarded a witness as what we would call a trusted third party, one who stands aside from the dispute and can tell it how it really was. The Romans did also use the word testis in a figurative way to mean testicle. The idea seems to have been that a testicle was a witness to a man's virility. And that's the whole story of the connection.
One reason for the confusion may be that swearing on the testicles is recorded in the Bible. The practice is mentioned in the Old Testament, though King James' version bowdlerized the reference in Genesis to "grasping the thigh". But there seems to be no evidence that the Romans — a long way away and in another era — used a similar method. In any case, the Biblical reference implies that the person is swearing on the testicles of the king, not on their own.
Incidentally, testis sometimes appeared in the form of testicles, a diminutive form; this was converted into English at the end of the fourteenth century first as testicle and then as testicle. The Latin testis, with its plural testes, has continued in medical use to the present day.