Can you tell the difference between female and male urine?

yes, I have heard it can be detected, but a test for determining sex of urine has to be given.
The "test" for determining the sex of urine is real easy: cap the bottle and shake it for about ten seconds. Male urine develops a foam on top. Female urine does not.
When I started a suboxone clinic a few years ago part of the requirement was I do a urine drug test once a week. I didn't want to stop smoking pot so I found a guy who was also using suboxone (AND ONLY SUBOXONE) and he pissed in a cup for me. He'd fill a bottle which i could split over four weeks. Id add a tablespoon of boiling hot water to the cup before I left the house and submerge the cup in a thermos of hot water. I never failed a test (over 2 years.) It is important to note that the place I pissed at sent it out so I don't know if the temp would be okay if the facility tests then and there. No one ever detected a males urine when I submitted my sample. Also important to note, many drug tests strip you down and you can't bring your purse in the room with you so know what facility you are using.
Foaming/non-foaming urine sounds like urban folklore to me...
Yes you can tell the difference based on the hormones contained in the urine. There will also be some shed cells in the urine which can be tested for XY vs XX chromosomes. That said - few labs testing urine actually run tests for these. If you are expecting to have to submit to a urine-based drug test and are considering trying to cheat with someone else's urine, the biggest problem isn't whether you are using urine from a different gender - it's that you are trying to cheat. (Also, if they are running the test according to best practices, you won't be able to substitute the urine anyway) Just quit doing the drugs you shouldn't be using in the first place and keep the rest of us safe!