The trial will commence at the Yours and Owls Festival taking place on March 1-2 in Wollongong on the NSW south coast.
The Minns Labor government announced in December it would allow a 12-month trial of pill-testing at music festivals - a practice some other states have already adopted and expanded - in NSW from early 2025.
"Let me be clear, no level of illicit drug use is safe and pill testing services do not provide a guarantee of safety," Health Minister Ryan Park said on Wednesday.
"However, this trial has been designed to provide people with the necessary information to make more informed decisions about drug use, with the goal of reducing drug-related harm and saving lives."
The free and anonymous service will allow festival goers to bring a small sample of substances they intend to consume to be analysed by qualified health staff to test for purity, potency and adulterants.
The government stressed "people will never be advised a drug is safe to use".
NSW Health and NSW Police are working closely with festival organisers and other stakeholders to set up the March trial.
"Pill testing is something we have been fighting for, for some time now," Ben Tillman, from Yours and Owls, said in a statement.
"While Yours and Owls maintains a zero-tolerance policy to illegal drugs, we are realists and see the abstinence-only approach as unhelpful."
Mr Tillman said pill testing was a proven harm minimisation strategy that had been successfully implemented in many countries for about 20 years.