I have a small project that does not contain a class to run a Spring Boot Application. In that class I only have some configuration and some repositories. I would like to test those repositories inside the small project.
For that, I have the following:
@SpringBootTest
@DataJpaTest
public class TaskRepositoryTest extends AbstractTestNGSpringContextTests {
@Autowired
private TaskRepository taskRepository;
@Test
public void test() {
taskRepository.save(new Task("open"));
}
}
But I get the following error
Caused by: java.lang.NoSuchMethodError: org.springframework.boot.jdbc.DataSourceBuilder.findType(Ljava/lang/ClassLoader;)Ljava/lang/Class;
Any idea what I have to do?
This works for me with Spring Boot 2.0.3, H2 and latest RELEASE testng:
LE:
In the previous version of the answer I've used
@SpringBootTest @DataJpaTest
but that seems to be the wrong way to do it. The following message would appear:Using
@ContextConfiguration
with@DataJpaTest
removes that warning and IntelliJ doesn't mark the mockedtaskRepository
as Could not autowire. No beans of 'TaskRepository' type found.