Junit ClientBuilder cant';产生新客户
我不熟悉Junit测试和jmockit。在我的项目中,我们必须测试get调用请求。下面是我的测试 公共类重新连接测试 {Junit ClientBuilder cant';产生新客户,junit,jmockit,Junit,Jmockit,我不熟悉Junit测试和jmockit。在我的项目中,我们必须测试get调用请求。下面是我的测试 公共类重新连接测试 { @可注入 私有字符串身份验证用户名; @注射的 私有字符串身份验证密码; @注射的 私人回应; @注射的 私有调用生成器; @注射的 私有SecurityContext SecurityContext; @测试 @注射的 rest连接器rest连接器; @注射的 私人伐木场支援伐木场支援; @注射的 私人记录器; @试验 public void testGetEmptyRes
@可注入
私有字符串身份验证用户名;
@注射的
私有字符串身份验证密码;
@注射的
私人回应;
@注射的
私有调用生成器;
@注射的
私有SecurityContext SecurityContext;
@测试
@注射的
rest连接器rest连接器;
@注射的
私人伐木场支援伐木场支援;
@注射的
私人记录器;
@试验
public void testGetEmptyResponse()
{
新期望()
{
{
response.getStatus();
结果=200;
}
{
restConnector.callGet((Invocation.Builder)any);
结果=响应;
}
};
最终字符串结果=restConnector.get(“test”,String.class);
assertNull(结果);
}
}
但是当我在下面的步骤中调试代码时
client=ClientBuilder.newBuilder().property(“connect.timeout”,毫秒数)
.register(JsonProvider.class)
.build();
我将有以下例外
java.lang.RuntimeException:java.lang.RuntimeException:RESTEASY003940:无法实例化MessageBodyReader能否为测试中的类添加代码?
@Injectable
private String authenticationUsername;
@Injectable
private String authenticationPassword;
@Injectable
private Response response;
@Injectable
private Invocation.Builder builder;
@Injectable
private SecurityContext securityContext;
@Tested
@Injectable
RestConnector<String> restConnector;
@Injectable
private LoggerSupport loggerSupport;
@Injectable
private Logger logger;
@Test
public void testGetEmptyResponse()
{
new Expectations()
{
{
response.getStatus();
result = 200;
}
{
restConnector.callGet((Invocation.Builder) any);
result = response;
}
};
final String result = restConnector.get("test", String.class);
assertNull(result);
}