They basically try to get an aggregate of certain gene or gene markers that are associated with a certain 'race' if you will. The problem is that in order to make an accurate account of these things you have to know a lot of information about who has what genes where the genes are at x point in time. Considering that race is such a nebulous concept to begin with all it can really tell you is that you share some genes as some people from place x.
The tests are not complete junk, but it's not nearly as definitive as some people try to suggest it.
An article from
Genetic Ancestry Tests Mostly Hype, Scientists Say
breaks it down more succinctly.
"If a test-taker is just interested in finding out where there are some people in the world that share the same DNA as them, then these tests can certainly tell them that," said Deborah Bolnick of the University of Texas in Austin. "But they're not going to tell you every place or every group in the world where people share your DNA. Nor will they necessarily be able to tell you exactly where your ancestors lived or [what race or social group] they identified with."