3
저희 회사에서는 코드 커버리지 요건이 90 %입니다. Cobertura, Enums and the Switch 성명
Cobertura 보고서를 실행
, 나는 단지 88.8 %의 범위를 얻고, 나는 다음과 같은 스위치 문을 강조보고하고있다 : 그것은 80 %의 범위를보고public TopBrandPrefix getPrefix() {
switch(brandParamType) {
case TOP12SUCHAS_AND:
return TopBrandPrefix.SUCHAS;
case TOP12COMME_ET:
return TopBrandPrefix.COMME;
case TOP12WIE_UND:
return TopBrandPrefix.WIE;
default:
return TopBrandPrefix.NULL;
}
}
. brandParamType는 다음과 같은 열거 형의이다 : 내 단위 테스트에서
public enum BrandParamType {
TOP123,
TOP456,
TOP123LINKED,
TOP456LINKED,
TOP12,
TOP12AND,
TOP12SUCHAS_AND,
TOP12COMME_ET,
TOP12WIE_UND
}
, 나는이 값의 각각 getPrefix를 호출하고, 그래서 내가 어떻게 여기에 100 % 가지 혜택을 받고 있지 않다 와서? 매우 유사한 테스트를 실행
@Test
public void testGetPrefixWithTOP123() {
TopBrandTouchpointParameterSource source = new TopBrandTouchpointParameterSource(urlComposer, TouchpointParameterHelper.BrandParamType.TOP123);
TopBrandTouchpointParameterSource.TopBrandPrefix prefix = source.getPrefix();
assertEquals(TopBrandTouchpointParameterSource.TopBrandPrefix.NULL, prefix);
}
@Test
public void testGetPrefixWithTOP456() {
TopBrandTouchpointParameterSource source = new TopBrandTouchpointParameterSource(urlComposer, TouchpointParameterHelper.BrandParamType.TOP456);
TopBrandTouchpointParameterSource.TopBrandPrefix prefix = source.getPrefix();
assertEquals(TopBrandTouchpointParameterSource.TopBrandPrefix.NULL, prefix);
}
@Test
public void testGetPrefixWithTOP123LINKED() {
TopBrandTouchpointParameterSource source = new TopBrandTouchpointParameterSource(urlComposer, TouchpointParameterHelper.BrandParamType.TOP123LINKED);
TopBrandTouchpointParameterSource.TopBrandPrefix prefix = source.getPrefix();
assertEquals(TopBrandTouchpointParameterSource.TopBrandPrefix.NULL, prefix);
}
@Test
public void testGetPrefixWithTOP456LINKED() {
TopBrandTouchpointParameterSource source = new TopBrandTouchpointParameterSource(urlComposer, TouchpointParameterHelper.BrandParamType.TOP456LINKED);
TopBrandTouchpointParameterSource.TopBrandPrefix prefix = source.getPrefix();
assertEquals(TopBrandTouchpointParameterSource.TopBrandPrefix.NULL, prefix);
}
@Test
public void testGetPrefixWithTOP12() {
TopBrandTouchpointParameterSource source = new TopBrandTouchpointParameterSource(urlComposer, TouchpointParameterHelper.BrandParamType.TOP12);
TopBrandTouchpointParameterSource.TopBrandPrefix prefix = source.getPrefix();
assertEquals(TopBrandTouchpointParameterSource.TopBrandPrefix.NULL, prefix);
}
@Test
public void testGetPrefixWithTOP12AND() {
TopBrandTouchpointParameterSource source = new TopBrandTouchpointParameterSource(urlComposer, TouchpointParameterHelper.BrandParamType.TOP12AND);
TopBrandTouchpointParameterSource.TopBrandPrefix prefix = source.getPrefix();
assertEquals(TopBrandTouchpointParameterSource.TopBrandPrefix.NULL, prefix);
}
@Test
public void testGetPrefixWithTOP12SUCH_AS() {
TopBrandTouchpointParameterSource source = new TopBrandTouchpointParameterSource(urlComposer, TouchpointParameterHelper.BrandParamType.TOP12SUCHAS_AND);
TopBrandTouchpointParameterSource.TopBrandPrefix prefix = source.getPrefix();
assertEquals(TopBrandTouchpointParameterSource.TopBrandPrefix.SUCHAS, prefix);
}
@Test
public void testGetPrefixWithTOP12COMME_ET() {
TopBrandTouchpointParameterSource source = new TopBrandTouchpointParameterSource(urlComposer, TouchpointParameterHelper.BrandParamType.TOP12COMME_ET);
TopBrandTouchpointParameterSource.TopBrandPrefix prefix = source.getPrefix();
assertEquals(TopBrandTouchpointParameterSource.TopBrandPrefix.COMME, prefix);
}
@Test
public void testGetPrefixWithTOP12WIE_UND() {
TopBrandTouchpointParameterSource source = new TopBrandTouchpointParameterSource(urlComposer, TouchpointParameterHelper.BrandParamType.TOP12WIE_UND);
TopBrandTouchpointParameterSource.TopBrandPrefix prefix = source.getPrefix();
assertEquals(TopBrandTouchpointParameterSource.TopBrandPrefix.WIE, prefix);
}
테스트 코드를 추가하십시오. – Markus
단위 테스트는 '기본'사례를 포함하여 네 가지 가능한 모든 경우를 다루고 있습니까? – Jesper
단위 테스트는 TopBrandPrefix – Xetius