Integration tests with Spring Boot and MySQL -


i familiar spring data jpa , test repositories kind of declaration (spring 4):

@runwith(springjunit4classrunner.class) @contextconfiguration(classes = {persistenceconfig.class}) @sql({"classpath:it-data.sql"}) public class myrepositoryit {      @autowired     private myrepository repository;      @test     public void sometest() {         ...     } } 

so in charge of creating mysql schema , tables test class inserts test data (it-data.sql), , src/test/resources/persistence.properties contains datasource config.

now want same thing in spring boot project. coded simple project works (a controller uses service retrieve data repository getting data mysql database).
problem not able code simple test tests repository (i don't want load whole app test repository), either context errors or datasource config errors.
starting from

@runwith(springrunner.class) public class myrepositoryit {      @autowired     private myrepository repository;      @test     public void sometest() {         ...     } } 

and duplicating src/main/resources/application.properties src/test/resources/application.properties (just changing schema name), tried tons of combinations using @datajpatest, @contextconfiguration(classes = application.class), @sql, @springboottest, @autoconfiguretestdatabase, @databasesetup, etc. nothing works.

so, knowing have mysql database exists tests, annotations should use insert data , test autowired repositories?
thanks.

you should mock classes used class want test. can use tool mockito.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -