zl程序教程

您现在的位置是:首页 >  Javascript

当前栏目

Spring boot 配置单元测试

2023-03-14 22:51:19 时间

添加依赖


<!--    测试    -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

写测试类


注意测试类的目录

image.png

测试类代码

【注意】

1、 类上面要写2行注解。第一行是运行环境,第二行classes = 你的启动类。

2、 测试类中方法上要加@Test

3、 测试类尽量写在src/test/java/下

@RunWith(SpringRunner.class)
@SpringBootTest(classes = MainApplication.class)
public class test01Service extends BaseServiceImpl {

    @Test
    public void selectMenus(){

        List<SyMenu> syMenus = dao.find("from SyMenu order by menuSort asc");
        for (SyMenu s : syMenus)
            System.out.println(s.toString());

    }
}