'SpringBoot Liquibase Oracle Junit test case execution fails

I have a SpringBoot application in which i use Liquibase to generate oracle schema and tables. When i run the application, it runs fine.

But when i try to run the Junit test case, it fails with below error,

Error creating bean name 'liquibase' defined in class path resource....
Migration failed for change set /db/changelog/....
Reason : liquibase.exception.DatabaseException: Schema "XYZ" not found; SQL statement

The schema and tables are all present in the Database.

Still, why do i get this error?

Any suggestions please.



Solution 1:[1]

I found an article on Medium regarding the Schema Not Found part of your error. Link: Fix - Schema Not Found and Why

In step 3, the article recommends spring users add a file in your resource folder and name it schema-h2.sql. Within the file they give this example:

-- CREATE DATABASE IF NOT EXISTS
CREATE SCHEMA IF NOT EXISTS testdb;

For step 4, you turn on your initialization-mode in your *.properties files. This will cause the schema-platform.sql files to be executed as expected.

spring.datasource.initialization-mode=embedded

When you reach step 5, make sure your platform name matches the *.sql file. the example they show in the screenshot in the article is shown below.

# DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
#spring.datasource.hikari.maximumPoolSize=8
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false;DB_CLOSE_ON_EXIT=FALSE;
spring.datasource.username=sa
spring.datasource.password=
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.platform=h2
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
spring.datasource.name=testdb

Then, double check all your schema names match perfectly, and you should be good to go.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 tabbyfoo