Cancer researchers in Europe analysed blood from 265 men with the disease.
They found those with multiple copies of a particular gene did not respond to abiraterone and enzalutamide - drugs commonly used to treat advanced cases.
More trials are needed but the team hope the test could prevent thousands of men undergoing unnecessary treatment and allow more personalised care.
The drugs abiraterone and enzalutamide are given to men whose cancer is no longer responding to traditional hormone therapy and has started to spread.
Costing less than £50, the test is a quick and relatively cheap way of preventing men from undergoing the side effects of therapy that will fail.
Lead researcher Dr Gerhardt Attard, from the Centre for Evolution and Cancer at the Institute of Cancer Research in London, said: "Abiraterone and enzalutamide are excellent treatments for advanced prostate cancer and some men can take these drugs for years without seeing a return of their cancer.
"But in other men, these drugs do not work well and the disease rapidly returns. Currently, there is no approved test to help doctors choose whether these are the best treatments for an individual.
"We have developed a robust test that can be used in the clinic to pick out which men with advanced prostate cancer are likely to respond to abiraterone and enzalutamide, and which men might need alternative treatments."
For the study, published in the journal Annals of Oncology, scientists took blood samples from patients taking part in three different clinical trials.
Dr Iain Frame, director of research at Prostate Cancer UK, said the test could be a significant step towards moving away from a "one-size-fits-all" approach to treatment.
About 46,000 men are diagnosed with prostate cancer in the UK every year, one in four of them at an advanced stage.