CALGARY -- Energy giant Suncor Energy has won another victory in a years-long legal battle over random drug and alcohol testing at its northeastern Alberta oilsands sites.

Suncor (TSX:SU) started randomly testing staff in safety-sensitive jobs in 2012, but the union representing many of those workers called it an infringement of privacy.

The majority of an arbitration tribunal ruled in favour of Unifor in 2014, but last year Alberta Court of Queen's Bench Justice Blair Nixon quashed that decision.

Unifor appealed Nixon's ruling, but three judges with the Alberta Court of Appeal unanimously dismissed the union's challenge in a decision released Thursday.

"The question before us is whether the reviewing justice selected the appropriate standard of review and applied it properly," the Appeal Court judges wrote.

"We hold that he did both."

The arbitration tribunal heard that, at the time of the grievance, there were about 10,000 workers at Suncor's oilsands sites at any given time, including nearly 3,400 represented by Unifor.

The company presented evidence of more than 2,200 incidents that involved drugs or alcohol, but did not break down how many involved unionized employees versus non-union members and contractors. In Thursday's ruling, the judges noted workers inside and outside the union regularly work side-by-side.

They also highlighted why safety is such a concern. Suncor's facilities around Fort McMurray, Alta., operate 24 hours a day, every day of the year and its employees work 12-hour shifts operating some of the biggest and most complicated industrial equipment in the world.

"The equipment includes heavy haul trucks that are as large as multi-storey buildings and weigh in excess of 400 tons, as well as cable and hydraulic shovels that can stand 21 metres tall."

The Appeal Court judges said the key question during arbitration was whether there was sufficient evidence of a widespread substance abuse problem that would warrant random drug testing at its sites, given the privacy issues at play.

"Rather than considering whether there was evidence of a problem in the workplace, the majority asked only whether there was evidence of such a problem specific to bargaining unit employees," the judges wrote.

"By unreasonably narrowing the evidence that it considered when deciding this issue, the tribunal majority effectively asked the wrong question, and therefore applied the wrong legal test."

The Appeal Court judges said they agree with Nixon that the matter should be heard by a fresh arbitration panel.

Unifor called the Court of Appeal decision a gross violation of workers' rights.

"This ruling supports an invasive and degrading policy that violates the fundamental rights of workers," said Unifor national president Jerry Dias.

"Safety is always our first priority but we know that random drug testing does not reduce accidents or improve safety."

Ken Smith, president of Unifor Local 707-A, said the fight will continue.

"We will take all available action to fight this abusive policy, including a potential motion to seek leave to appeal to the Supreme Court of Canada."

Suncor spokeswoman Nicole Fisher said the company was happy with the decision.

"Nothing is more important than protecting ourselves and others from harm. That's why safety is one of our core values and we're very pleased with this decision," she said.

"We strongly believe that this program will contribute to a safer workplace and ultimately save lives."