The test determines aptitude. Choice is separate
The purpose of the test is to determine which faction is the best fit for an individual. Although people usually choose the faction that their parents are in, and even more frequently choose the faction determined by their test results (most of whom, yes, are probably Divergent).
As to why people can choose at all, why not let them choose? The system may have been oppressive and manipulated by outside forces, but they weren't trying to stifle every spark of individuality and choice. Quite the opposite, in fact: producing more Divergent was a major goal of the program.
Why didn't the government suspect that Tris was Divergent?
Well, first, it's not really the government that one would have to worry about, since most of them are Abnegation, and Tris's parents occupy important positions therein. It's more about whether Erudite's leader suspects.
She is the danger Tori and my mother warned me about, the danger of
being Divergent. Sitting right in front of me.
And she most certainly did:
“Correct. The aptitude test is by far my greatest achievement as a
scientist,” she replies. “I looked up your test results, Beatrice.
Apparently there was a problem with your test. It was never recorded,
and your results had to be reported manually. Did you know that?”
“Did you know that you’re one of two people ever to get an Abnegation
result and switch to Dauntless?"
She was suspicious for exactly the reason you mentioned.
The other, of course, was Tobias. This is a very small number, and Jeanine almost certainly suspected that both were Divergent.
I understand only one thing: She is lying to me. She doesn’t care
about the technology—she suspects that something is awry with my test
results. Just like the Dauntless leaders, she is sniffing around for
the Divergent. And if my mother wants Caleb to research the simulation
serum, it is probably because Jeanine developed it.