It depends on what kind of test you are talking about.
Amniocintesis or chorionic villii sampling are tests done for different reasons during pregnancy, and are only done when the need is medically serious for the baby because they carry risk of miscarriage. The DNA extracted can be tested for paternity at that time, but no doctor does either of these tests for that reason alone.
Prenatal paternity testing can be done by a simple blood draw from (the arm of) the mother and swab from the possible father(s). It is not dangerous in the slightest to the baby. But, it is very costly (ten times the cost of DNA testing done after the baby is born) and some of the labs out there offering it are basically rip-off places. If you do test for paternity before the baby is born, use either Ravgen or the DDC. They are the two labs with the very best names. Just be ready to drop some serious money.
I heard its not safe but some people still get it done i would say just wait untill the baby gets here so your not risking your babies life