It doesn't have to be for free. I know someone who would "hire" potential candidates for a 2-week contract, and based their skill on the code they write during that time. If the candidate doesn't end up getting hired afterwards, he still gets paid for his time. It's a win-win.