vendredi 6 mars 2015

mysql for junit testing in spring

Is there any way to use MySQL for JUnit testing with Spring?


I ask this because I have a lot of store procedures in MYSQL and I have noticed that H2 is not working with SPs.


Edit:


Right now my configuration for src/main looks like:



@ComponentScan
@EnableAutoConfiguration
@EnableJpaRepositories
public class Application {

public static void main(String[] args) {
ConfigurableApplicationContext applicationContext = SpringApplication.run(Application.class, args);
}
}


spring.datasource.url=jdbc:mysql://localhost/mydb
spring.datasource.username=user
spring.datasource.password=pw
spring.datasource.driver-class-name=com.mysql.jdbc.Driver


Spring works fine with this configuration. It reads the application.properties, sees the spring.datasource.* and knows that I have set a datasource.


Everything is fine here.


Now, in tests I use something like:



@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {Application.class})
@Transactional
public class TxServiceTest {

}


This is not going to run the tests against MySQL database. It will run the tests with H2 database. I need to use MySQL for testing because I am using many stored procedures.


I have tried many other combinations but none of them works. What am I missing here?


Aucun commentaire:

Enregistrer un commentaire