Recommendation type: Uncovered code
Configurable in Preferences: Yes
Filter category: Uncovered code
This type of recommendation helps you identify code that is not covered.
See Increasing Code Coverage for details.
In the following example, the UncoveredCode class contains two methods: the normalize
method that contains a conditional statement, and the readChar
method that catches an exception:
public class UncoveredCode { public int normalize(int value) { if (value > 100) { return 100; } else { return value; } } public char readChar(Reader reader) throws Exception { try { return (char)reader.read(); } catch (IOException e) { throw new Exception("Encountered IO exception", e); } } } |
The following test cases have been created to cover the methods:
public class UncoveredCodeTest { @Test public void testNormalize() throws Throwable { UncoveredCode underTest = new UncoveredCode(); int value = 0; // UTA: default value int result = underTest.normalize(value); assertEquals(0, result); } @Test public void testReadChar() throws Throwable { UncoveredCode underTest = new UncoveredCode(); Reader reader = mock(Reader.class); int readResult = 'c'; when(reader.read()).thenReturn(readResult); char result = underTest.readChar(reader); assertEquals('c', result); } } |
When the test cases are run, UTA detects that they do not fully cover the code of the normalize
and readChar
methods:
As a result, UTA displays an Uncovered code recommendation for each of the methods:
Clicking the Clone test links automatically creates a duplicate of the selected test case to help you cover the uncovered lines (see Cloning and Updating a Test Case for details).