I
never heard of anyone around me required to do a drug test for work. May be different for people carrying guns, like police and hunters, but that's because of gun license requirements.
A drug test may be legal, or suggested, when there is reasonable suspicion someone was high during work hours. Maybe air traffic controllers and similar professions need to be evidently clean. Otherwise I don't think drug tests are legal in Germany. Even asking about consumption is illegal in most cases.