Given how WordPress is written and how it interacts with a database and given how its not very much OOP oriented, is there a way to unit test a theme? is there a way unit test a framework (not a theme framework) that interacts with WordPress, that is, for example, can you write a unit test for dealing with the loop, dealing with the widgets?

If so does any one have any examples? I know how to write unit tests, but I have never tried to write one for a theme.

I wrote the Travis-CI powered PHPunit testing library for Jigoshop and Easy Digital Downloads both of which are Ecommerce WP plugins developed on Github. The library employed could be easily converted to work for themes. The nice thing about the Travis-CI powered suite is that we can use it to quickly test multiple PHP and WP versions. If you're theme is a premium theme, and thus putting it on a free Github repo isn't an option, the suite works on Private Github repos with Travis-CI.

Alternatively, you can use the one found in Jigoshop and use commandline powered PHPUnit.