Testing Dynamic Datasource Operations with OrderMapper in SpringBoot-Labs
This test suite validates the OrderMapper functionality in a dynamic datasource environment using Baomidou and Spring Boot. It examines core database operations through unit tests that verify order selection and insertion capabilities.
Test Coverage Overview
Implementation Analysis
Technical Details
Best Practices Demonstrated
yudaocode/springboot-labs
lab-17/lab-17-dynamic-datasource-baomidou-02/src/test/java/dynamicdatasource/mapper/OrderMapperTest.java
package dynamicdatasource.mapper;
import cn.iocoder.springboot.lab17.dynamicdatasource.Application;
import cn.iocoder.springboot.lab17.dynamicdatasource.dataobject.OrderDO;
import cn.iocoder.springboot.lab17.dynamicdatasource.mapper.OrderMapper;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public class OrderMapperTest {
@Autowired
private OrderMapper orderMapper;
@Test
public void testSelectById() {
for (int i = 0; i < 10; i++) {
OrderDO order = orderMapper.selectById(1);
System.out.println(order);
}
}
@Test
public void testInsert() {
OrderDO order = new OrderDO();
order.setUserId(10);
orderMapper.insert(order);
}
}