I'm currently using Spring Boot 1.5.4 alongside Junit 5 and Java 8.
I want to setup integration tests on multiple entries that are stored in a csv file using Junit's ParameterizedTest.
Here is the code:
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class MatchingIT {
@Autowired
private TestRestTemplate template;
@ParameterizedTest
@MethodSource(names = "vehicles")
void nonRegressionTests(EDIVehicle vehicle) {
ResponseEntity<Vehicle> v = template.getForEntity("/match/" + vehicule.getId(), Vehicle.class);
Assert.assertNotNull(v);
}
private static Stream<EDIVehicle> vehicles() throws IOException {
InputStream is = new ClassPathResource("/entries.csv").getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
return br.lines().map(toVehicle);
}
private static Function<String, EDIVehicle> toVehicle = (line) -> {
String[] p = line.split("\\|");
return new EDIVehicle(p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7], p[8], p[9], p[10], p[11], p[12]);
};
}
I know from the documentation that:
If you are using the @SpringBootTest annotation, a TestRestTemplate is automatically available and can be @Autowired into your test.
The thing is that I do use the SpringBootTest annotation but when I run the tests, the TestRestTemplate is constantly null. Maybe I missed something.
EDIT: I do have the exact same problem while adding @RunWith(SpringRunner.class) annotation