测试指南

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)
Bingosoft            updated 2018-11-01
上一篇:获取客户端信息 下一篇:文档指南

results matching ""

    No results matching ""