Q. Is a male permitted to produce semen for testing purposes?
A. The basic principle is that the emission of semen must be restricted to marital relations. The Biblical source of this principle is the prohibition of “wasting seed” (hash’chatat zera), as described in the story of Er and Onan (Gen. 38).
The Talmud discusses hash’chatat zera in Y’vamot 65 where the sages say that the command to be fruitful and multiply applies to males because God said to Jacob p’reh ur’veh, in the singular. Hence a male must not do any action designed to prevent conception. Rabbi Yochanan ben B’roka replies that God said p’ru ur’vu, in the plural, to Adam and Eve. Hence the male’s responsibility is no higher than the female’s. The halachah, however, follows the sages.
There are rabbinic responsa which permit the emission of semen for testing purposes in cases of genito-urinary conditions, but no general permission can be derived from this for the emission of semen other than in the course of marital relations. Every situation has to be looked at on its own.