The Reagan administration told the Supreme Court today that mandatory drug tests for some railroad workers and U.S. Customs Service employees are vital to public safety and confidence in government. Attorney General Dick Thornburgh, in an unusual move, appeared himself to plead for testing of rail workers after train accidents. ``This is a case about railway safety,'' he said. It is about ``the hazards created by use of drugs and alcohol by those in charge of trains.'' Solicitor General Charles Fried, the administration's top courtroom lawyer, defended the Customs Service drug testing program. ``There is rather special, urgent and symbolic significance'' in assuring the public that the agency responsible for preventing drug smuggling has a drug-free work force, Fried said. ``The Customs Service is indeed entitled to take a fine filter to show to itself, its workers and the public that (workers) are not involved in drug use,'' he said. The drug tests were attacked as a ``humiliating invasion of privacy'' by Lois Williams, representing the Customs Service workers. ``Innocent persons have a great deal of reason to be apprehensive,'' she said. Lawrence Mann, an attorney for the railway workers, said the drug tests are unconstitutional because they are incapable of proving on-the-job impairment. ``Neither the alcohol nor the drug test can demonstrate impairment,'' he said. The tests can show the presence of a residue from a drug that may have been taken by ``someone 60 days ago in the privacy of home.'' The two cases will provide a crucial test for mandatory drug testing in the American workplace. Thornburgh's appearance underscored the importance of today's two-hour argument session. Benjamin Civiletti was the last attorney general to argue a case before the justices when he appeared in 1980 to present the Carter administration's side in a case involving the deportation of an alleged Nazi. Thornburgh last argued a case before the high court in 1977 when he headed the Justice Department's criminal division. In today's cases, the justices agreed to decide whether the nation's railroads may require all employees involved in accidents to take drug tests; and whether the Customs Service may impose the tests for those seeking drug-enforcement jobs. Both cases involve governmental authority to test workers for the presence of drugs. The eventual rulings by the court, expected sometime in 1989, will not deal with drug tests for private employees. But the decisions could have an important psychological impact on whether businesses will demand that their workers undergo such tests. Tests conducted by federal, state or local governments will be affected directly by the court's action. In the railroad case, the Federal Railroad Administration issued regulations in 1985 aimed at alleviating ``a significant safety problem'' caused by alcohol and drug use among employees. The agency, an arm of the U.S. Department of Transportation, generally requires railroads to take blood and urine specimens after accidents, incidents and rules violations. The 9th U.S. Circuit Court of Appeals ruled in February that the tests are unreasonable searches banned by the Constitution's Fourth Amendment. ``Accidents, incidents or rule violations, by themselves, do not create reasonable grounds for suspecting that tests will demonstrate alcohol or drug impairment in any one railroad employee, much less an entire train crew,'' the appeals court said. Government lawyers have said that from 1972 through 1983, railroad accidents linked to drug or alcohol abuse killed 42 people, injured 61 and caused some $19 million in property damage. In the Customs Service case, the government contends the need to fight drug smuggling justifies mandatory tests for those applying for or holding drug-enforcement jobs. Workers in such sensitive jobs must provide urine samples in restroom stalls as a person overseeing the procedure waits outside the stall. Testing was authorized under an executive order President Reagan signed in 1986. The Reagan administration has said the tests are needed to prevent agents who use drugs from being bribed or blackmailed. Any sacrifice of personal privacy is outweighed by the need to stop drug smuggling, the administration said. The National Treasury Employees Union, in challenging the tests, said they subject workers to a humiliating invasion of privacy. The 5th U.S. Circuit Court of Appeals upheld the tests for Customs Service workers in such sensitive jobs.