Skip to content

Mock Server的作用:对于特定的Request请求,返回特定的Response响应。

License

Notifications You must be signed in to change notification settings

liuwen766/mockserver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

在平时的接口测试工作中,系统的业务很少是孤立存在的,大部分业务相互之间都是需要关联调用的。 前端与后端的相互协作实现业务逻辑,接口或服务之间相互协作,或者使用第三方服务等。通常的处理方 式是搭建一个临时的server,模拟服务,提供数据进行联调测试。

Mock Server的作用:对于特定的Request请求,返回特定的Response响应。Mock数据的方式常用 的有两种。

方式一:Java API以编程方式,如下:

new MockServerClient("localhost", 1080)
    .when(
        request()
            .withMethod("POST")
            .withPath("/login")
            .withBody("{username: 'foo', password: 'bar'}")
    )
    .respond(
        response()
            .withStatusCode(200)
            .withCookie(
                "sessionId", "2By8LOhBmaW5nZXJwcmludCIlMDAzMW"
            )
            .withHeader(
                "Location", "https://www.mock-server.com"
            )
    );

方式二:json方式,如下:

  {
		"httpRequest": {
			"path": "/api/user/outer/query/userStatus",
			"method": "GET"
		},
		"httpResponse": {
			"body": {
				"state" : "OK",
				"body" : 1,
				"requestId" : "b8fe75be1a0647b09294143e0697ee9d"
			}
		}
	}

mockserver部署包文档结构: mockserver |——mockserver:启动脚本配置 |——conf:配置 | |——logging.properties:日志配置 | |——mock-server.json:mock数据配置 |——lib:放有jar包 |——log:日志 |——mock-server.sh:启动脚本

jar包生成步骤: mockserver-netty包下运行如下命令: mvn clean package -DskipTests 生成: mockserver-netty/target/mockserver-netty-5.11.1-jar-with-dependencies.jar Java启动: java -jar mockserver-netty-5.11.1-jar-with-dependencies.jar -serverPort 1080,1081 -logLevel INFO -Dmockserver.initializationJsonPath=“期望配置文件”

maven插件启动: mvn -Dmockserver.serverPort=1080 -Dmockserver.logLevel=INFO org.mock-server:mockserver-maven-plugin:5.11.1:runForked 停止: mvn -Dmockserver.serverPort=1080 org.mock-server:mockserver-maven-plugin:5.11.1:stopForked

Mock Server UI: http://localhost:1080/mockserver/dashboard

记录request/response: curl -v -X PUT "http://localhost:1080/mockserver/retrieve?type=REQUEST_RESPONSES"


MockServer            Tweet Build status GitHub license GitHub stars Trello Backlog  Join Slack

Documentation

For usage guide please see: www.mock-server.com

Change Log

Please see: Change Log

Community

Chat Join Slack
Feature Requests Github Issues
Issues / Bugs Github Issues
Backlog Trello Backlog

Versions

Maven Central mockserver

Maven Central contains the following MockServer artifacts:

In addition MockServer SNAPSHOT artifacts can also be found on Sonatype.

Node Module & Grunt Plugin

NPM Registry contains the following module:

Docker Hub

Docker Hub contains the following artifacts:

Helm Chart
MockServer Clients
Previous Versions
Version Date Git & Docker Tag / Git Hash Documentation Java API REST API
5.11.2 08 Nov 2020 mockserver-5.11.2 / eb84f2 Documentation Java API 5.11.x REST API
5.11.1 22 Jul 2020 mockserver-5.11.1 / 361e5c Documentation Java API 5.11.x REST API
5.11.0 08 Jul 2020 mockserver-5.11.0 / 756758 Documentation Java API 5.11.x REST API
5.10.0 24 Mar 2020 mockserver-5.10.0 / 14124d Documentation Java API 5.10.x REST API
5.9.0 01 Feb 2020 mockserver-5.9.0 / eacf07 Documentation Java API 5.9.x REST API
5.8.1 23 Dec 2019 mockserver-5.8.1 / f0e9ab Documentation Java API 5.8.x REST API
5.8.0 01 Dec 2019 mockserver-5.8.0 / 7c9fc5 Documentation Java API 5.8.x REST API
5.7.2 16 Nov 2019 mockserver-5.7.2 / 7c9fc5 Documentation Java API 5.7.x REST API
5.7.1 09 Nov 2019 mockserver-5.7.1 / 0ca353 Documentation Java API 5.7.x REST API
5.7.0 01 Nov 2019 mockserver-5.7.0 / b58bc5 Documentation Java API 5.7.x REST API
5.6.1 21 Jul 2019 mockserver-5.6.1 / aec1fb Documentation Java API 5.6.x REST API
5.6.0 21 Jun 2019 mockserver-5.6.0 / 8f82dc Documentation Java API 5.6.x REST API
5.5.4 26 Apr 2019 mockserver-5.5.4 / 4ffd31 Documentation Java API 5.5.x REST API
5.5.1 29 Dec 2018 mockserver-5.5.1 / 11d8a9 Documentation Java API 5.5.x REST API
5.5.0 15 Nov 2018 mockserver-5.5.0 / 06e6fd Documentation Java API 5.5.x REST API
5.4.1 20 Jun 2018 mockserver-5.4.1 / 7cd5de Documentation Java API 5.4.x REST API
5.3.0 25 Dec 2017 mockserver-5.3.0 / ad62bb Documentation Java API 5.2.x REST API
5.2.3 17 Dec 2017 mockserver-5.2.3 / e81c53 Documentation Java API 5.2.x REST API
5.2.2 12 Dec 2017 mockserver-5.2.2 / b47090 Documentation Java API 5.2.x REST API
5.2.1 11 Dec 2017 mockserver-5.2.1 / 834ec8 Documentation Java API 5.2.x REST API
5.2.0 10 Dec 2017 mockserver-5.2.0 / ccb4d2 Documentation Java API 5.2.x REST API
5.1.1 06 Dec 2017 mockserver-5.1.1 / 664afb Documentation Java API 5.1.x REST API
5.1.0 05 Dec 2017 mockserver-5.1.0 / bbdda1 Documentation Java API 5.1.x REST API
5.0.1 05 Dec 2017 mockserver-5.0.1 / 975fb8 Documentation Java API 5.0.x REST API
5.0.0 04 Dec 2017 mockserver-5.0.0 / ed5d13 Documentation Java API 5.0.x REST API
4.1.0 30 Nov 2017 mockserver-4.1.0 / 4e37b2 Documentation Java API 4.x.x REST API
4.0.0 28 Nov 2017 mockserver-4.0.0 / 8b2455 Documentation Java API 4.x.x REST API

Issues

If you have any problems, please check the project issues and avoid opening issues that have already been fixed. When you open an issue please provide the following information:

  • MockServer version (i.e. 5.11.2)
  • How your running the MockServer (i.e maven plugin, docker, etc)
  • MockServer log output, at INFO level (or higher)
  • What the error is
  • What you are trying to do

Contributions

Pull requests are, of course, very welcome! Please read our contributing to the project guide first. Then head over to the open issues to see what we need help with. Make sure you let us know if you intend to work on something. Also check out Trello Backlog to see what is already in the backlog.

Feature Requests

Feature requests are submitted to github issues. Once accepted they will be added to the backlog. Please check out Trello Backlog to see what is already in the backlog.

Maintainers

About

Mock Server的作用:对于特定的Request请求,返回特定的Response响应。

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published