Byoona Ntairaho believes the tests will deter men from having sex with underage pupils for fear of being named and shamed in parents' meetings.
In 2000, when Mr Ntairaho took on the headship of Kamurasi Demonstration primary in Masindi, more than a third of the girls were dropping out because they were pregnant. And the school had not achieved one top grade in its primary leaving exams for 10 years.
"Local boys and men were using these girls for sex for as little as 300 Ugandan shillings (less than 15p), which the girls were using to buy cassava or popcorn at break time," he says, referring to so-called "sugar daddies".
The 36-year-old head also discovered some parents were trading their daughters' virginity for paltry sums. "Mothers were encouraging their girls to have sex to generate income. Many were being impregnated because there were no rules governing them and they did not know their rights."
Uganda is turning the tide on teen pregnancy. Ten years ago almost half of its 15 to 19-year-old girls had children - the highest rate in Africa. In 2001, the proportion had dropped to a third, but 6,000 girls still had to leave school to give birth that year.
Pregnancy testing is not widespread in primaries but Kamurasi has many older pupils tempted back to school by the promise of free education.
Since 2000 the number of pupils has almost doubled (half of whom are female) and six girls gained the top grade in their leaving exams last year. "I think my parents now realise the girl child is important," says Mr Ntairaho.
Next week a BBC4 documentary, Sex Education, part of a series called African School, will show a team of doctors and nurses march into Kamurasi in a scene reminiscent of a Carry On film.
To select the girls for external examination, Mr Ntairaho asks questions such as, "Who has breasts?" and "Who has a boyfriend?"
Viewers see final-year student, Christine Shadiya, 18, one of three girls who fears she is pregnant and receives counselling. "Now I will sell papyrus mats to get my own money," she says.
Mr Ntairaho follows up testing and harassment complaints with home visits, and, in extreme cases, police reports. And he encourages pregnant girls to resume their education - but at other schools.
"I don't want the other pupils to think that they can return easily if they get pregnant," he says.
African School is part of the BBC's Africa Lives season. It is supported by BBC World Class, which encourages schools to establish links between classrooms across the globe.
Sex Education will be broadcast on BBC4 next Thursday, June 30, at 8.30pm.
For details of the BBC Africa initiatives, see bbc.co.ukworldclass and www.bbc.co.ukafricalivesMore about African schools at www.open2.netafricanschool