How do I test my localhost WordPress project with VirtualBoxVM?

If I understand you, don’t use ‘localhost’. That only works if you are testing from the same machine that is running the server. (A virtualized machine counts as a different machine.) Give your server (the machine running the server) a static IP address– something like 192.168.1.5– and use that instead of ‘localhost’. That will work for any machine on your subnet.