Trenton - An H.I.V. test is about to become as routine as an ultrasound for pregnant women in New Jersey.

Under a bill signed into law on Wednesday, all pregnant women in the state will be tested for the virus as part of their prenatal care unless they object. The law also requires testing for newborns if the H.I.V. status of the mother is unknown.

The new testing procedures are some of the most aggressive H.I.V.-prevention measures in the country for pregnant women and newborns, making New Jersey one of just a handful of states with laws requiring some form of prenatal testing.

According to the Kaiser Family Foundation, which researches health issues, a dozen states require doctors to offer H.I.V. tests to their pregnant patients. But just three - New York, Connecticut and Illinois - have mandatory testing for newborn babies. Four others - Michigan, Arkansas, Texas and Tennessee - have laws similar to New Jersey's policy of testing pregnant women.

New Jersey's new law goes into effect in six months.

Prenatal H.I.V. testing laws are meant to help stem the infection of newborns. If it is known that a pregnant woman is H.I.V. positive, doctors can take steps to prevent infection like prescribing antiretroviral drugs and delivering the child through a Caesarian section.

"Early detection is the key," Senator Loretta Weinberg, a Democrat from Bergen County who sponsored the bill, said in a statement. "This measure is a huge step forward in terms of protecting all babies while helping to educate mothers."

Under the law, women will be tested early in their pregnancies and again in their third trimesters unless they refuse. If a woman refuses, it will be noted, and an H.I.V. test will be performed on the newborn unless the mother has religious objections.

According to the Kaiser Family Foundation, in 2001, New Jersey ranked 19th in the nation in the percentage of residents ages 18 to 64 who have ever been tested for H.I.V. Nearly 48 percent said they had been tested, compared with a national average of 45.6 percent, the foundation said.