怎样在小程序里实现标题的更改
613
2022-11-03
Just-API是一个健壮的,基于规范的HTTP APIs (REST, GraphQL)测试框架
Just-API
If this project helps you in anyway, Please consider making a donation
Become a backer or sponsor on Patreon.One-time donation via PayPal
Just-API is a declarative, specification based test framework for REST, GraphQL APIs. Users can test APIs without writing code, but they can also tap into code when they want to. It reads API test specification from YAML files and runs them in serial/parallel mode. Test reports can be generated in several formats including HTML and jsON.
In simple terms, users build a test suite by providing a set of request and response validation specification in a YAML file. Each suite can have one or more specs. Just-API builds the request, sends it to server and validates response as per the specification. One can choose to validate any or all of following
Status codeHeadersCookiesResponse JSON bodyResponse JSON schema
or Provide a custom Javascript function to validate the response
Find more here
Links
DocumentationGitter ChatroomGoogle GroupIssue Tracker
Features
Runs test suites in parallel/serial modeSupports all widely used HTTP methodsSupports x-www-form-urlencoded requests, Multipart requests, File uploadsBuilt-in Response Validation Constructs(Headers, Cookies, Status code, JSON body, JSON schema)Custom Response validator functionsSupports running custom inline or module javascript sync/async functionsSupports Hooks (Before All, After All, Before Each, After Each, Before Test, After Test)Custom suite configurationChained Request flowsDefine/override Request path, query params, path params, headers, body at runtimeSuite and test context for reuseSupports importing specs from one or more test suitesIntrasuite and Intersuite spec dependenciesReusing test specificationRetry failed testsLooping: Generate 'n' number of tests with a listBuilt-in HTML, JSON reportersCan generate reports in multiple formats for the same runLogging HTTP request/response data for failed testsProper error reportingCan run tests matching with a given pattern/stringSkipping tests with specificationDisable or Enable redirectionsReports test durationAllows user to plug-in custom reporters
See all features
Getting Started
To run just-api, you will need Node.js v7.10.0 or newer.
Installation
$ npm install just-api
Following is a simple example showing usage of Just-API.
$ mkdir specs$ vim specs/starwars_service.yml
Write following suite in your editor
meta: name: Star Wars suiteconfiguration: scheme: https host: swapi.co base_path: /apispecs: - name: get Luke Skywalker info request: path: /people/1/ method: get response: status_code: 200 headers: - name: content-type value: !!js/regexp application/json json_data: - path: $.name value: Luke Skywalker
Back in the terminal
$ ./node_modules/.bin/just-api ✓ get Luke Skywalker info (1216ms) Done: specs/starwars_service.yml (Passed)0 skipped, 0 failed, 1 passed (1 tests)0 skipped, 0 failed, 1 passed (1 suites)Duration: 1.3s
Testing GraphQL APIs
Following example tests a GraphQL API that returns Person info for a given name.
Create a YAML suite and run just-api.
meta: name: GraphQL Starwars serviceconfiguration: host: swapi.graph.cool scheme: httpsspecs: - name: Get Details of a character request: method: post headers: - name: content-type value: application/json payload: body: type: json content: query: > { Person(name: "Luke Skywalker") { name, id, gender } } variables: null operationName: null response: status_code: 200 json_data: - path: $.data.Person.name value: "Luke Skywalker"
A chained request flow with hook and custom validation
When you need to test complex chained API flows, run dependencies in hooks to fetch pre-requisite data and pass it to actual test.
Following example shows how to run dependencies using a hook, get data and validating response with a custom validator function.
meta: name: Starwars suiteconfiguration: scheme: https host: swapi.co base_path: /apispecs: - name: get R2-D2 info request: path: /people/3/ method: get response: status_code: 200 json_data: - path: $.name value: R2-D2 - name: search R2-D2 info before_test: run_type: inline inline: function: !js/asyncFunction > async function() { var response = await this.runSpec('get R2-D2 info'); var jsonData = JSON.parse(response.body); this.test.query_params = { name: jsonData.name }; } request: path: /people method: get response: status_code: 200 custom_validator: run_type: inline inline: function: !!js/function > function() { var jsonData = JSON.parse(this.response.body); var r2d2 = jsonData.results.find(result => result.name === 'R2-D2'); if (!r2d2) throw new Error('R2-D2 not returned in search results'); }
Note: You can also place custom JS functions in a module and specify the function name, module path in YAML to import.
More advanced stuff can be done with Just-API. Documentation says it all. Take a look at Just-API Website for detailed documentation.
If you are looking to use Docker to run Just-API, you might want to checkout Just-API docker boilerplate here
Maintainer
Kiran kiran.6d.hex@gmail.com
License
MIT-licensed
References
Just-API, Testing HTTP-based APIs (REST, GraphQL)
Donation
If this project helps you in anyway, Please consider making a donation
Become a backer or sponsor on Patreon.One-time donation via PayPal
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~