Xorg-gtest makes it easy to write test cases for a dummy headless X.org server. It can also run tests using a running X11 server.