You can't beat a drugs test for THC as its stored in your fat cells and can take months to become clean after heavy usage. I've heard of people getting done for drug driving days after thier last smoke.
You also have to consent to a test so its upto you if you take it or not, but you could be sacked. Really depends on the type of job you have as to whether you could then challenge the dismissal.
Unless you operate machinery there isn't a lawful reason for them to be testing you.