デバッグのときにいちいちリモートにつなぐのは効率が悪いので、StringからHTMLPageを生成する方法
import java.io.IOException; import java.net.URL; import com.gargoylesoftware.htmlunit.StringWebResponse; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.HTMLParser; import com.gargoylesoftware.htmlunit.html.HtmlPage; public class HtmlUnitTest { public static void main(String[] args) throws IOException { // TODO Auto-generated method stub URL url = new URL("http://www.example.com"); StringWebResponse response = new StringWebResponse("<html><head><title>Test</title></head><body></body></html>", url); WebClient webClient = new WebClient(); HtmlPage page = HTMLParser.parseHtml(response, webClient.getCurrentWindow()); System.out.println(page.getTitleText()); webClient.close(); } }