测试指南
Since 0.3 (Experimental)
jmms
从0.3开始支持单元测试,提供以下功能:
- 根据API的元数据自动生成单元测试
- 通过
json
文件编写自定义单元测试 - 通过命令行工具一键运行单元测试
- 通过浏览器访问所有单元测试的定义
启用单元测试
jmms
单元测试没有内置在核心引擎中,而是通过插件的方式进行提供。
- 在
pom.xml
中添加依赖:
<dependency>
<groupId>org.leapframework</groupId>
<artifactId>jmms-testing</artifactId>
<version>${jmms.version}</version>
<optional>true</optional>
</dependency>
- 重新启动
$ jmms run
- 浏览器访问
http://localhost:8080/$test
,可看到json
所有单元测试的定义:
{
"tests": {
"it_should_works": {
"source": "~/tests/it_should_works.json",
"id": "it_should_works",
"name": "it_should_works",
"title": "Itshouldworks",
"type": "default",
"steps": [
{
"title": "Step1",
"type": "rest",
"exec": "GET/",
"params": {},
"asserts": [
{
"title": "Assertion1",
"type": "script",
"expr": "Assert.equals(200,rest.response.status)"
}
]
}
]
}
}
}
运行单元测试
在工程根目录下执行命令行:
$ jmms test
可看到单元测试运行结果:
✓ Validate swagger spec
✓ It should works (~/tests/it_should_works.json)
Default
✓ GET / (gen)
3 passing (48ms)