Username Validation Parameterized
As your Java knowledge increases, you've decided to revisit the username validator from Chapter 1. Since it depends on a single output, it can be shortened using parameterization.
Consider all the failure outcomes of the isValidUsername() method. Condense them all in a single @ParameterizedTest.
The necessary JUnit packages have been imported for you.
Diese Übung ist Teil des Kurses
Introduction to Testing in Java
Anleitung zur Übung
- Use the correct annotation to mark a test as a parameterized test.
- Add a null input to the test.
- Add the annotation to the input values in the test.
- Mark the value type of the inputs.
Interaktive Übung
Vervollständige den Beispielcode, um diese Übung erfolgreich abzuschließen.
public class Main {
public static void main(String[] args) {
launchTestsAndPrint(UsernameValidatorTest.class);
}
}
class UsernameValidatorTest {
// Annotate with the correct annotation for parameterized test
@____
// Add the annotation for inputting a null input
@____
// Add the annotation for inputting values and the type of the inputs
@____(____ = {"john doe", "jd"})
void isValidUsername_returnsFalse_whenSpaces(String username) {
boolean actual = UsernameValidator.isValidUsername(username);
assertFalse(actual);
}
}