I am trying to write an integration test in micronaut.
I have a controller class:
@Controller("/hello")
public class HelloController {
@Inject
private HelloRepository helloRepository;
@Get("/")
public HttpResponse get() {
return HttpResponse.ok(helloRepository.findAll());
}
}
I am trying to write an integration test for it like:
@MicronautTest
public class HelloControllerSpec {
@Inject
EmbeddedServer embeddedServer;
@BeforeEach
void setUp() {
initMocks(this);
}
@Test
public void testIndex() throws Exception {
try(RxHttpClient client = embeddedServer.getApplicationContext().createBean(RxHttpClient.class, embeddedServer.getURL())) {
client.toBlocking().exchange("/hello").status();
}
}
}
But I keep getting the error:
No backing RepositoryOperations configured for repository. Check your configuration and try again
My application.yml file that I put under "src/test/java/resources/" has the following datasource implementation:
datasources:
default:
url: jdbc:h2:mem:devDb
driverClassName: org.h2.Driver
username: sa
password: 'sa'
schema-generate: CREATE_DROP
dialect: H2
jpa:
default:
packages-to-scan:
- 'com.myproject.project'
properties:
hibernate:
hbm2ddl:
auto: update
show_sql: true
I have also included this in my build.gradle file
runtime 'com.h2database:h2'
Is there any way to solve this?
Edit: This is my repository class
@Repository
public interface HelloRepository extends CrudRepository<BufferConditionEntity, Long> {}