Que*_*ueg 5 java junit unit-testing jmockit
这来自官方的JMockit教程:
@Test
public void doSomethingHandlesSomeCheckedException() throws Exception
{
new Expectations() {
DependencyAbc abc;
{
abc.stringReturningMethod();
returns("str1", "str2");
result = new SomeCheckedException();
}
};
new UnitUnderTest().doSomething();
}
Run Code Online (Sandbox Code Playgroud)
是否有可能说明相反的情况,即多个结果和一个返回 - 我需要抛出2个异常,然后才返回一个好的值.我正在寻找的东西是这样的:
abc.stringReturningMethod();
returns(new SomeCheckedException(), new SomeOtherException(),"third");
Run Code Online (Sandbox Code Playgroud)
这不起作用,JMockit无法将这些异常转换为String(返回类型stringReturningMethod)
写这样:
abc.stringReturningMethod();
result = new SomeCheckedException();
result = new SomeOtherException();
result = "third";
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6601 次 |
| 最近记录: |