I heard that in order to make a paternity test in Germany, the consent of both spouses is needed. If the husband has doubts about whether he is the father of a child born in wedlock, can he insist on such a test in order to avoid paying child support in the event of a divorce?
Yes, a father can contest paternity
A man married to the mother at the time of birth is legally the father. He has 2 years to contest this in court. Without going into details, the court has the power to order a paternity test if necessary.