java不用启动项目测试方法
package com.example.demo;
import com.example.demo.mapper.OrderMapper;
import com.example.demo.model.Order;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
/**
* @Author yaoChengWei
* @Date 2024-12-17 16:35:21
*/
@SpringBootTest
@RunWith(SpringRunner.class)
public class ShardingSphereProApplicationTests {
@Resource
private OrderMapper orderMapper;
@Test
public void addOrder() {
try {
for (int i = 0; i < 10; i++) {
Order order = new Order();
order.setTid((long) i);
order.setTname("订单" + i);
order.setGoodsId(Long.valueOf("" + (1000 + i)));
order.setTstatus("1");
System.out.println(order);
int affectedRows = this.orderMapper.insert(order);
System.out.println("受影响的行数:" + affectedRows); // 输出受影响的行数
}
} catch (NumberFormatException e) {
e.printStackTrace();
}
}
@Test
public void queryAll() {
this.orderMapper.selectList(null).forEach(System.out::println);
}
@Test
public void queryAll11() {
this.orderMapper.getBaseInfos().forEach(System.out::println);
}
}