Usually a person in the family who has had cancer has the test first. If a cancer gene is found, other members of the family can choose to have a test.
Sometimes, no living relative with cancer can be tested. In this case you may be offered a genetic test. But only if your family history strongly suggests there could be a cancer gene in your family.
If you have a family history of cancer, and have Ashkenazi Jewish or Polish ancestry, you may also be able to have a genetic test without a relative who has had cancer being tested first.