内容简介:这个源码项目演示了如何基于测试框架在进行集成测试时,请保持简单易用需要依赖:
这个源码项目演示了如何基于测试框架 JUnit 和 Zerocode 对spring-boot+spring-data(JPA)和H2 in-memory DB应用进行集成测试,让你的日常生活变得轻松。
在进行集成测试时,请保持简单易用
需要依赖:
<dependency>
<groupId>org.jsmart</groupId>
<artifactId>zerocode-<b>rest</b>-bdd</artifactId>
<version>1.2.x</version>
</dependency>
Junit单元测试在目录test/java/integrationtests/crudtests下,可单独运行API GET测试:
mvn -Dtest= test e.g. > mvn -Dtest=TestGetOperations test
集成测试在目录:
src/test/java/integrationtests/IntegrationTestSuite.java
可直接运行:
mvn -Dtest=IntegrationTestSuite test
Maven中是通过<goal>integration-test</goal>启动集成测试的:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
<configuration>
<includes>
<include>integrationtests.IntegrationTestSuite.java</include>
</includes>
</configuration>
</goals>
</execution>
</executions>
</plugin>
<include>integrationtests.IntegrationTestSuite.java</include>的代码如下:
@EnvProperty(<font>"_${env}"</font><font>)
@TargetEnv(</font><font>"application_host.properties"</font><font>)
@TestPackageRoot(</font><font>"integration_tests"</font><font>) </font><font><i>//You can point this to any package you need -or- use Junit Suite runner to point to individual test classes</i></font><font>
@RunWith(E2eJunitSuiteRunner.<b>class</b>)
<b>public</b> <b>class</b> IntegrationTestSuite {
}
</font>
@EnvProperty("_${env}") 允许您针对多个环境运行相同的测试套件,只需提及env名称即可。通过Jenkins传递环境参数,并在CI中动态选择特定于环境的属性文件。
在Jenkins中设置“env = cit”,然后选择“application_host_cit.properties”并运行。设置 -Denv = sit,然后寻找并选择“application_host_sit.properties”并运行。
如果env未提供,则默认为“application_host.properties”,默认情况下通过@TargetEnvs设置
mvn goal在特定环境中通过Jenkins目标运行时配置以下内容,例如 -
对于CI:mvn clean install -Denv = ci
对于SIT:mvn clean install -Denv = sit
并确保:resources_host_cit.properties和application_host_sit.properties等在资源文件夹或类路径中可用
在本地测试:
如何在Local上验证@EnvProperty(“_ $ {env}”)测试?
在不同的端口上运行2个应用程序JAR实例
java -jar -Dserver.port = 9090 SpringbootRestInMemoryDB-1.0.0-SNAPSHOT.jar
java -jar -Dserver.port = 7070 SpringbootRestInMemoryDB-1.0.0-SNAPSHOT.jar
针对环境配置文件运行IntegrationTestSuite
mvn -Denv = cit -Dtest = IntegrationTestSuite测试
(针对application_host_cit.properties运行测试。验证来自在9090端口上运行的JAR的日志。)
mvn -Denv = sit -Dtest = IntegrationTestSuite测试
(针对application_host_sit.properties运行测试。验证来自在7070端口上运行的JAR的日志。)
mvn -Dtest = IntegrationTestSuite测试
(针对在默认端口8080上运行的application_host.properties运行测试。)
@RunWith(E2eJunitSuiteRunner.class)
启动SpringBoot应用程序,然后逐个触发测试。
报告
在/ target文件夹下查找详细的测试报告(zerocode-junit-interactive-fuzzy-search.html
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- iOS 中使用Jenkins进行持续集成
- 在Shell中进行独立的集成测试
- .net core 集成 sentry 进行异常报警
- 使用 CODING 进行 Hexo 项目的持续集成
- 使用 CODING 进行 Spring Boot 项目的集成
- SpringBoot集成Shiro进行权限控制和管理的示例
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
高中数学公式定律及要点透析
牛胜玉 编 / 2011-2 / 9.80元
《PASS绿卡图书:高中数学公式定律及要点透析(人教A版)(必修+选修)(第9次修订)》精选例句:时尚鲜活例句,再现巩固单词;延伸拓展:搭配用法辨析,提升运用能力;真题例句:精选真题例句,紧密联系高考。便于携带:三年教材词汇,方便随时记忆;附赠录音:用耳朵记单词,让学习零空隙。一起来看看 《高中数学公式定律及要点透析》 这本书的介绍吧!