Not able to access H2 database console during JUnit testing. Since the database will be up and running only when the test is running, I am trying to have a breakpoint or a sleep command to hold the test execution to access http://localhost:8080/h2-console in the browser, but getting "This site can’t be reached" error.
Sleep command I am using : TimeUnit.MINUTES.sleep(2);
POM.xml
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1;Mode=PostgreSQL
spring.datasource.username=sa
spring.datasource.password=sa
hibernate.hbm2ddl.auto=create
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console
spring.jpa.hibernate.ddl-auto=none
spring.jpa.properties.hibernate.default_schema=
logging.level.root=DEBUG
hibernate.show_sql=true
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.hibernate.use-new-id-generator-mappings=true
hibernate.dialect=org.hibernate.dialect.H2Dialect
To have access to the h2 console you need to spin up the whole application not just the persistence layer there for you can only do it in @SpringBootTest.
Also, you should enable the web endpoint and not use mock during the test.
Finally, do not block all the threads during the test so the h2 console can process the incoming requests.
Suppose we have a Person entity a PersonRepository and we have configured H2. Here is the test code and configuration you need to do in one image: