The research, in Science Translational Medicine, suggests two biomarkers can identify who will benefit from surgery, the BBC reported.
A UK fertility expert said the test, which will take at least a year to bring to the clinic, was "encouraging".
Male infertility is responsible for about half of cases of infertility.
Men who produce no sperm can sometimes be helped to father a biological child through fertility treatment if they have normal sperm that can be extracted surgically.
Others will never be able to father a child naturally and need to use donor sperm.
With current technology, the only way to find out if a man has viable sperm is to carry out surgery to look for sperm in the testes.
The new test, developed by scientists in Canada, has identified two biomarkers in sperm, which can be used to predict whether sperm retrieval will be successful.
Dr Keith Jarvi of the Lunenfeld-Tanenbaum Research Institute, Mount Sinai Hospital in Toronto, Canada, said the holy grail of his research was to find a way to help men avoid unnecessary testicular biopsies.