I was wondering about this question if you are having trouble running unit tests for my spring application.
Take the following example:
@SpringBootTest
@RunWith(SpringRunner.class)
public class AlbumDTOConverterTest {
@Autowired
private AlbumDTOConverter albumDTOConverter;
@Test
public void ToEntity_ReturnValue_NotNull() {
AlbumDTO albumDTO = new AlbumDTO("Summer album", new Date(), "This summer, we have made some wonderfull photos. Have a look!", null);
assertNotNull(albumDTOConverter.toEntity(albumDTO));
}
}
To do it @Autowiredright, I run a container with a test class annotation @SpringBootTest.
The thing is, I think I'm doing it wrong. In my opinion, I would rather just create a new instanceone AlbumDTOConverterby simply using the operator newinstead of using spring IoD.
What do you guys think about this?
source
share