@Test(timeout=X)
基本上我需要注释的相反行为。
我要解决的问题是以某种方式检测该方法永远不会结束(作为正确的行为)。我假设如果该方法在 X 秒后没有停止,我确信“它永远不会结束”。
谢谢!
@Test(timeout=X)
基本上我需要注释的相反行为。
我要解决的问题是以某种方式检测该方法永远不会结束(作为正确的行为)。我假设如果该方法在 X 秒后没有停止,我确信“它永远不会结束”。
谢谢!
你可以试试这个:
@Test
public void methodDoesNotReturnFor5Seconds() throws Exception {
Thread t = new Thread(new Runnable() {
public void run() {
methodUnderTest();
}
});
t.start();
t.join(5000);
assertTrue(t.isAlive());
// possibly do something to shut down methodUnderTest
}