springboot工程工程名有异常

由于未提供博客具体内容,无法给出包含关键信息的摘要。

在Spring Boot工程中搭建单元测试框架,可按以下步骤操作: ### 测试类存放位置 Spring Boot中单元测试类应写在`src/test/java`目录下,可以手动创建具体测试类,若使用IDEA,还能通过IDEA自动创建测试类,也可使用快捷键⇧⌘T(MAC)或者Ctrl + Shift + T(Window)来创建[^1]。 ### 编写单元测试代码示例 以下是两个不同的单元测试代码示例: #### 示例一 ```java @RunWith(SpringRunner.class) @SpringBootTest public class PracticeControllerTest { @Autowired private PracticeService practiceService; @Test public void test() { String aaa = practiceService.aaa(); System.out.println(aaa); } } ``` 此示例中,`@RunWith(SpringRunner.class)`用于指定运行测试的运行器,`@SpringBootTest`表示这是一个Spring Boot测试。通过`@Autowired`注入需要测试的`PracticeService`类,然后在`test`方法中调用其方法进行测试[^2]。 #### 示例二 ```java @RunWith(SpringRunner.class) @SpringBootTest(classes = Application.class) public class AtrributeDataMapperTest { private static final Logger logger = LogManager.getLogger(AtrributeDataMapperTest.class); @Autowired private AtrributeDataMapper mappper; @Test public void testGetColumnValues_Level3_Cable() { Integer instanceId = 2230; String tableName = "t_cable"; Integer level = 3; String field = "Length"; List<Object> data = mappper.getColumnValues(instanceId, tableName, level, field); data.forEach(System.out::println); } } ``` 该示例同样使用`@RunWith(SpringRunner.class)`和`@SpringBootTest`,不同的是`@SpringBootTest`的`classes`属性指定了Spring Boot的启动类的`class`(如`Application.class`)。若不加`classes`属性,当前测试类必须在启动类所在的包或其子包中,否则会在运行时抛出异常。通过`@Autowired`注入需要测试的`AtrributeDataMapper`类,在`testGetColumnValues_Level3_Cable`方法中调用其方法进行测试[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值