As Saaid Khan mentioned in New SharePoint Developer Features in VS2010 SP1 – Unit Testing and IntelliTrace, you can create unit tests for projects that reference Microsoft.SharePoint.dll.  For the visually minded, Belgian SharePoint MVP Serge Luca has a demo at his OneDrive.

You can also use the MSDN Library to help you along this path. For more information, Walkthrough: Verify SharePoint Code by Using Unit Tests.

Alternatively, you can use Microsoft Pex and Moles to write isolated unit tests. For more information, see http://research.microsoft.com/en-us/projects/pex/pexsharepoint.pdf.