While discussing my Pull Request ([1]) for JDK-8176270 ([2]) with Jeanette Winzenburg I came across two questions that I would like to ask the community regarding test cases:
1) How fine-grained to we want tests to be? Is it ok to test two (somewhat similiar) things at once or should a separate test case be written? e.g. this test case of mine: @Test public void replaceSelectionAtEndWithListener() { StringBuilder selectedTextLog = new StringBuilder(); StringBuilder selectionLog = new StringBuilder(); textInput.setText("x xxx"); textInput.selectRange(2, 5); textInput.selectedTextProperty().addListener((__, ___, selection) -> selectedTextLog.append("|" + selection)); textInput.selectionProperty().addListener((__, ___, selection) -> selectionLog.append("|" + selection.getStart() + "," + selection.getEnd())); textInput.replaceSelection("a"); assertEquals("|", selectedTextLog.toString()); assertEquals("|3,3", selectionLog.toString()); assertEquals("x a", textInput.getText()); } Will test the selectedTextProperty AND the selectionProperty at the same time. Is this acceptable/desireable or should the test case be split into two separate tests? 2) When fixing bugs, is it ok to not only provide a test case that will fail before the fix and run successfully after the fix but also provide additional test cases with the intention of preventing regressions? Ideally of course such tests should already exist but what if they are not. In my case I wanted to add a test case to "prove" that redo() will work in the presence of a shortened text and I would also like to have a general test case about selection properties and text property. What's the general rule here? Best regards, Robert [1] https://github.com/openjdk/jfx/pull/138 [2] https://bugs.openjdk.java.net/browse/JDK-8176270