-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JUnit 4 to 5 recipe for JUnit4 Parameterized Tests #81
Labels
enhancement
New feature or request
Comments
Recipe for
Before: @RunWith(Parameterized.class)
public class VetTests {
private String firstName;
private String lastName;
private Integer id;
public VetTests(String firstName, String lastName, Integer id) {
this.firstName = firstName;
this.lastName = lastName;
this.id = id;
}
@Test
public void testSerialization() {
Vet vet = new Vet();
vet.setFirstName(firstName);
vet.setLastName(lastName);
vet.setId(id);
Vet other = (Vet) SerializationUtils
.deserialize(SerializationUtils.serialize(vet));
assertEquals(vet.getFirstName(), other.getFirstName());
assertEquals(vet.getLastName(), other.getLastName());
assertEquals(vet.getId(), other.getId());
}
@Parameters(name="{index}: {0} {1} - {2}")
public static List<Object[]> parameters() {
return Arrays.asList(new Object[] {
new Object[] { "Otis "TheDog", 124 },
new Object[] { "Garfield", "TheBoss", 126 });
}
} After: public class VetTests {
private String firstName;
private String lastName;
private Integer id;
public void initVetTests(String firstName, String lastName, Integer id) {
this.firstName = firstName;
this.lastName = lastName;
this.id = id;
}
@ParameterizedTest(name = "{index}: {0} {1} {2}")
@MethodSource("parameters")
public void testSerialization(String firstName, String lastName, Integer id) {
initVetTests(firstName, lastName, id);
Vet vet = new Vet();
vet.setFirstName(firstName);
vet.setLastName(lastName);
vet.setId(id);
Vet other = (Vet) SerializationUtils
.deserialize(SerializationUtils.serialize(vet));
assertEquals(vet.getFirstName(), other.getFirstName());
assertEquals(vet.getLastName(), other.getLastName());
assertEquals(vet.getId(), other.getId());
}
public static List<Object[]> parameters() {
return Arrays.asList(new Object[] {
new Object[] { "Otis "TheDog", 124 },
new Object[] { "Garfield", "TheBoss", 126 });
}
} Reference info
|
pway99
added a commit
that referenced
this issue
Mar 24, 2021
…Junit 5 Jupiter ParameterizedTest equivalent. Fixes #81
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Discovered while testing
Boot2Junit4to5Migration
onspring-batch
create a new recipe for converting JUnit4 Parameterized tests
spring-batch parameterized AlmostStatefulChunkRetryTests
The text was updated successfully, but these errors were encountered: