The guide below explains how to install OS X Yosemite 10.10 in a virtual machine using the free and powerful VirtualBox.
Legal disclaimer: This guide aims to explain how to create a virtual machine on a regularly purchased Apple computer, running a genuine Mac OS X operating system, for testing purposes only.
Howto
Download Yosemite from the App Store
Open Terminal.app
Install iesd, to customize OS X InstallESD: gem install iesd
Turn install image into base system: iesd -i "/Applications/Install OS X Yosemite.app" -o yosemite.dmg -t BaseSystem