当前位置: 首页> 健康> 养生 > 小程序 网站 开发_小程序大概需要多少钱_株洲专业seo优化_网站广告费一般多少钱

小程序 网站 开发_小程序大概需要多少钱_株洲专业seo优化_网站广告费一般多少钱

时间:2025/7/10 3:03:50来源:https://blog.csdn.net/weixin_43891901/article/details/144817874 浏览次数:0次
小程序 网站 开发_小程序大概需要多少钱_株洲专业seo优化_网站广告费一般多少钱

文章目录

    • POM依赖引入
    • 业务层测试代码
    • Web层测试代码
    • 生成测试类文件

在工作中我用的最多的单元测试框架是Junit4。通常在写DAO、Service、Web层代码的时候都会进行单元测试,方便后续编码,前端甩锅。

POM依赖引入

        <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId></dependency>

业务层测试代码

在这里插入图片描述

package org.example.service;import org.example.mapper.UserMapper;
import org.example.pojo.User;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;import javax.annotation.Resource;
import java.util.List;@RunWith(SpringRunner.class)
@SpringBootTest
class UserServiceTest {@Resourceprivate UserMapper userMapper;@Testvoid getAllUsers() {}
}

Web层测试代码

package org.example.controller;import org.example.pojo.User;
import org.example.service.UserService;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;import javax.annotation.Resource;import static org.junit.jupiter.api.Assertions.*;
@RunWith(SpringRunner.class)
@SpringBootTest
class UserControllerTest {@Resourceprivate UserService userService;@Testvoid getUserById() {}
}

生成测试类文件

可以借助IDEA直接Go to生成业务代码的测试类

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

关键字:小程序 网站 开发_小程序大概需要多少钱_株洲专业seo优化_网站广告费一般多少钱

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: