# customer **Repository Path**: chenyuan_1990/customer ## Basic Information - **Project Name**: customer - **Description**: No description available - **Primary Language**: Java - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-09-07 - **Last Updated**: 2020-12-18 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 客户管理程序 ## 问题 * 给定一个基于 Spring Boot 的客户管理程序(Customer),包含生成客户和查询所有客户的功能 * 任务 * 采用不同的方式增加组件测试 * 不同的触发点 * 针对Controller进行组件测试 * 针对Service进行组件测试 * 针对Repository(DAO)进行组件测试 * 不同的数据库交互方法 * 使用Repository进行组件测试 * 使用SQL进行组件测试 * 使用DBUnit进行集成测 * 要求: * 组件测试和单元测试既可分别运行也可合并运行 * 组件测试环境与开发环境应使用不同的数据库 * 用Maven和IDE两种途径进行测试 ## 作业 * 在组件测试驱动下完成客户修改和查询所有客户的功能 ## 学习目的: * 掌握组件测试的概念和原理 * 掌握组件测试的方法 ## 提示: * 创建程序 * 使用 Spring Boot Starter 创建项目 * https://start.spring.io * Starter:Web、JPA、JDBC、H2 * 在pom.xml中增加设置 * assertJ * swagger2/swagger-ui * 编辑 application.yml(见程序) * Enable Swagger UI ``` @EnableSwagger2 @SpringBootApplication public class CustomerApplication { public static void main(String[] args) { SpringApplication.run(CustomerApplication.class, args); } } ``` * 编写程序 * 运行 * 方法1: ``` mvn spring-boot:run ``` * 方法2: ``` mvn clean package java -jar target/gs-rest-service-0.1.0.jar ``` * 方法3: run CustomerApplication in IDE * h2 console: http://localhost:8080/h2 * JDBC URL : jdbc:h2:./h2-dev * api doc: http://localhost:8080/swagger-ui.html * 组件测试 * 增加专门用于组件测试案例的目录integrationtest * pom.xml配置: * 通过 build-helper-maven-plugin 将 integrationtest 中的测试源码和资源加入Maven * 通过 maven-surefire-plugin 配置是否可忽略单元测试(默认不忽略) * 通过 maven-failsafe-plugin 配置组件测试 * 组件测试案例命名:XxxIT.java * 通过IDEA运行测试 * 配置Run Configuration,使用Pattern方式配置3个Run: * UnitTest (Pattern:.*Test) * IntegrationTest (.*IT) * AllTest(.*) * 通过命令行运行测试 * 运行单元测试和组件测试:``` mvn verify ``` * 只运行组件测试:```mvn verify -DskipUnitTest=true ``` * 只运行单元测试:```mvn test```