This is parameterized test in JUnit:
@ParameterizedTest
@ValueSource(strings = {"Username", "User123", "Another username", "Another_username" })
@DisplayName("should evaluate acceptable usernames as correct")
public void shouldEvaluateAcceptableUsernamesAsCorrect(String username) {
assertThat(UsernameValidator.validate(username)).isTrue();
}
After that in test results section in IntelliJ it's visible for which parameters test failed - and it's very convenient.
In ScalaTest it is also possible to write parameterized test:
class UsernameValidatorTests extends AnyFunSuite with Matchers {
val correctUsernames = Table("Username", "User123", "Another username", "Another_username")
test("should evaluate acceptable usernames as correct") {
forAll (correctUsernames) { (name: String) =>
UsernameValidator.validate(name) shouldBe true
}
}
}
But in this solution it's only one single test for all cases.
Is it possible to achievie effect from JUnit in ScalaTest?

