EDMONTON -- A union that represents 3,000 oilsands workers at Suncor Energy sites in Alberta has won a court injunction against random drug testing.

Unifor Local 707-A had argued that random testing would be a violation of workers' rights and privacy.

Calgary-based Suncor has said random tests are needed to bolster safety and wanted to start its program this month.

In his ruling, Queen's Bench Justice Paul Belzil said the privacy rights of employees are just as important as safety.

"In my view the balance of convenience favours granting the injunction," Belzil said in a written judgment released Thursday.

"The request by Suncor to increase the scope of drug and alcohol testing by implementing random testing would necessarily impact employees who have no drug and alcohol issues and who have not been involved in workplace incidents."

Belzil noted that Suncor already has non-random drug and alcohol testing and that granting the injunction would not result in an unsafe work environment.

He said both parties agree that the Suncor workplace is dangerous, but agree on virtually nothing else.

Suncor and the union have been battling over random drug tests since 2012. Unifor has sought leave to appeal an earlier court ruling to the Supreme Court of Canada.

Belzil said if leave to appeal is granted, both sides should co-operate to resolve the case as quickly as possible.

If the high court decides not to hear the case, Belzil said Suncor and Unifor should take the case to arbitration next year.

Suncor and Unifor officials were not immediately available for comment.

In earlier court cases Suncor presented evidence of thousands of incidents that involved drugs or alcohol, but did not break down how many involved unionized employees versus non-union members and contractors.

Suncor (SU.TO) has also highlighted why safety is a concern.

The company's facilities around Fort McMurray operate 24 hours a day, every day of the year and employees work 12-hour shifts operating some of the biggest and most complicated industrial equipment in the world.