Since I'm going to forget this if I don't write it down, in some cases you really want to test 'as if you're using a browser'. I.e. open a webpage, click on this link... The project you're looking for is HtmlUnit Haven't played around with it too much, but it's pure java - no browser necessary. If you want to use a browser, and 'drive' around with it, use selenium (it can spawn a Firefox/chrome browser, let it open pages, etc.)
This is a simple blog to help me remember those cool code snippets which I used. Either by copy, or by cobbling... I do not intend this to be read by people except for me and my bad mind.