A sure test, giving an incontestable result.
In the California Gold Rush in the second half of the 19th century, prospectors and dealers needed to be able to distinguish gold from base metal. Gold doesn't react to most acids as other metals do, although it does dissolve in Aqua regia (a mixture of hydrochloric acid and nitric acid). To confirm that a find was gold it was given 'the acid test'. Various other tests can be made by the use of acid and these are all called 'acid tests'.
The earliest citation I have found of a figurative use of the phrase (i.e. one where no actual acid is referred to) is from the Wisconsin paper The Columbia Reporter, November 1845:
"Twenty-four years of service demonstrates his ability to stand the acid test, as Gibson’s Soap Polish has done for over thirty years."
A punning variant of the term arose in the 1960s hippy community. The 'acid test' in that context determined whether users could cope with the psychological demands of taking the drug LSD (lysergic acid diethylamid) or simply 'acid'. This is cited in Maurer and Vogel's Narcotics and Narcotic Addiction, 1967:
"A common phrase amongst [LSD] users is 'can you pass the acid test?'"
See other phrases that were coined in the USA.