我正在编写两个 Junit 测试用例来测试超时
@Test
public void connectionTimeoutTest()
{
String myurl = "http://serverip:serverport/context";
URL url = new URL(myurl);
URLConnection con = url.openConnection();
//how to check connectionTimeout but not socket time out
//what I think
//is it good enough to check with a server ip that does not exist ?
}
@Test
public void socketTimeoutTest()
{
String myurl = "http://localhost:serverport/context";
URL url = new URL(myurl);
URLConnection con = url.openConnection();
//how to check successful connection and timesout at socket (or port)
//what I think
//IP should exist (so it is localhost) but should not be listening on the port
}
我在这里很困惑,因为我不确定我的方法是否正确。每种情况有哪些例外?另外,是否可以根据 Exceptions 进行区分?
还有其他我错过的时间吗?
提前致谢