I have a strange problem with my unit test.. My goal is to run test on a H2 database and not on my Mysql database..
Actually the strange thing is that when i click on maven test it runs the app, trying to connect to mysql.. crash and the start with the h2 database and unit test fail..
@ExtendWith(SpringExtension.class)
@SpringBootTest
// @ActiveProfiles("test") // Without this it runs on my mysql and works.. ,
// with this annotation the behaviour is described above
@Transactional
class BelugaprojectsApplicationTests {
@Autowired
private ICheckConfigService iCheckConfigService;
@Autowired
private CheckConfigJpaRepository checkConfigJpaRepository;
@Test
void getAllCheckConfigDeploiement() {
assertThat(iCheckConfigService.getAllCheckConfigDeploiement(
Integer.parseInt(AppConstants.DEFAULT_PAGE_NUMBER),
Integer.parseInt(AppConstants.DEFAULT_PAGE_SIZE),
"id").getTotalElements() > 0);
}
}
Properties
datasource:
url: jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1
username: root
password:
jpa:
open-in-view: true
hibernate:
ddl-auto: create-drop
Running with the test profile activated it throws
Caused by: org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "HISTORIQUEDEPLOIEMENT" non trouvée
Table "HISTORIQUEDEPLOIEMENT" not found; SQL statement:
alter table historiquedeploiement add constraint FK134pkswiisobg18okjr9pegt7 foreign key (id_namespace) references namespace (id) [42102-200]
Table "CHECKCONFIGDEPLOIEMENT" non trouvée
Table "CHECKCONFIGDEPLOIEMENT" not found; SQL statement:
Dependencies
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>