简体   繁体   中英

What is check h2 database after unit test

I have use h2 database for unit test follow this example .

In my application.properties:

server.port=8888
spring.h2.console.enabled=true

In unit test:

@RunWith(SpringRunner.class)
@SpringBootTest
public class CustomerServiceTest {

    @Autowired
    private CustomerDao customerDao;

    @Test
    public void testCreateCustomer(){
        BigDecimal id = customerDao.createCustomer(new Customer(1, "PhucN"));
        Assert.assertEquals(id,1);
    }
}

I have a problem, when I run unit test, h2 database create in memory but after finish test, database is drop and I cannot check data insert into h2 database.

Update question: I use mybatis, it's not ORM(hibernate, JPA)

maybe this example would be more complete,

https://www.baeldung.com/spring-boot-testing

you supposed to test the data that you inserted during unit test with select and assertion, not check it manuly after test.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM