私はJUnit
を使用して2つの方法をテストしていますが、私が直面している問題は、個別に実行するとテストケースがうまく動作するということです。一緒に。 2番目の方法ではNull
の状態をテストしていますので、RuntimeException
が必要です。最初の方法では、boolean
のブロックをテストしています。これは設定しています。今のところLine Coverage
は81%、Branch Coverage
は66%ですが、テストケースでは、私がフルラインとブランチカバレッジを取得していないために何が間違っているのか分かりません。テスト中のJUnit and Coberturaコードカバレッジ
クラス:
private static ObjectMapper mapper;
public static ObjectMapper initialize(ClientConfiguration config) {
if(mapper == null) {
synchronized (ObjectMapperHolder.class) {
mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY,true);
//Allows Users to overwrite the Jackson Behavior of failing when they encounter an unknown property in the response
if(config.isJsonIgnoreUnknownProperties()) {
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
}
}
return mapper;
}
public static ObjectMapper getInstance() {
if(mapper == null) {
throw new RuntimeException("The initialize() method must be called before the ObjectMapper can be used");
}
return mapper;
}
JUnits:
@Test
public void testInitialize() throws Exception {
ClientConfiguration configuration = new ClientConfiguration();
configuration.setJsonIgnoreUnknownProperties(true);
ObjectMapperHolder.initialize(configuration);
assertNotNull(configuration);
}
@Test(expected=RuntimeException.class)
public void testGetInstance() throws Exception {
ObjectMapperHolder.getInstance();
}
具体的にどのラインがカバーされていないかご存知ですか?この情報を出力するレポートファイルが必要です。 – kichik