这是我的班级结构
public class OrderRuntimeException extends RuntimeException
{
private final Field field;
public OrderManagementServiceRuntimeException(String messege, MyError myError)
{
super(messege);
this.field = field;
}
}
public Class MyError{
String name;
Sttring description;
public MyError(String name, String description){
this.name = name;
this.description = description;
}
}
public void getOrders(Order order){
.......
throw new OrderRuntimeException("Invalid Order",new MyError("Illegale","this is an illegal..."))
}
我想用 Junit 测试这个异常和 MeError 类型的对象(名称和描述)。我写了这个
public class MyTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test(expectedExceptions = OrderRuntimeException.class, expectedExceptionsMessageRegExp = "Invalid Order")
public void testSetRequestTime_invalidRequestDTOImplType()
{
thrown.expect(......);
}
}
我使用 @Rule .. 来获取 throw.expect() 功能。但是我无法从这个测试中得到 MyError 类型的对象。请发表评论或回答,如果有人对解决方案有想法。
萧十郎
相关分类