You can always use the EICAR test file.
As for detecting VM environments, there are various methods for this, some of which are :
Detecting VME artifacts in the registry or processes. - I think some variants of Phatbot do this.
Detecting VME artifacts in memory.
Detecting VME specific processor instructions.
Looking for specific virtual hardware.
Joanna Rutkowska's Red Pill was written to detect virtual machines by figuring out the location of the Interrupt Descriptor Table and based on the location determine if the OS was running in a VM or not.
Scoopy
www.trapkit.de is another tool that does VM detection.