当前位置: 首页 > 软件库 > Web应用开发 > Web框架 >

testing-hapi

授权协议 Readme
开发语言 JavaScript
所属分类 Web应用开发、 Web框架
软件类型 开源软件
地区 不详
投 递 者 陆展
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

testing-hapi

Example Hapi-backed API Server with testing, CI, and Swagger documentation generator.

Updated and tested with latest hapi packages as of 1/16/2018.

How to run

Requires Node v8.12.0+

yarn install #install dependencies
  yarn start # start server
  yarn test # run tests

Details

  • Notable npms

    • hapi, joi
      • hapi is a popular web/services nodejs framework. It is strict about routing and validation out of the box and has a mature plugin/extension system. I've used express for a long time, but since trying hapi, I haven't really looked back. On the surface the two frameworks look similar. In my experience though, I found that hapi managed to scale much better with increasing complexity and made it easier to test, debug, and write better code.
      • joi is an awesome schema/object definition and validation library. This project uses it to enforce API input/output validation and generate documentation.
    • hapi-swagger
      • Swagger is an API framework and standard. hapi-swagger is a hapi plugin that generates awesome interactive API documentation & UI right from our code API definitions. I gotta say... it's really nice to keep everything in one place.
    • lab
      • lab is hapi's version of mocha. It's a test runner, nicely packaged with a linter and code-coverage reporter. Nothing you wouldn't expect here. (Unless you've never written tests)
  • Testing

    • Unit Tests (/test/unit/*)
      • Functions containing business logic are defined in isolation from the framework making them testable without a running server
    • Functional Tests (test/functional/*)
      • These tests are meant to target the API endpoints, covering functionality end-to-end.
      • We should try to write these tests in a way that they become easily exportable to run automatically via tools like New Relic Synthetics
    • ESLint
      • lab also includes a linter (eslint by default), which is executed when tests run. The default configuration can be customized via the .eslintrc.json file.
    • Code Coverage
      • lab analyzes the code and returns the code coverage ratio when running the test. It also points out which lines of code are missing coverage. A nice reminder to write tests for any newly added functionality.
  • Documentation

    • hapi-swagger is configured in app.js and generates a very nice html page with an interactive Swagger compatible API.
    • Once your server is running locally, visit http://localhost:3000 to check out the docs.
    • My typical workflow is to write the documentation first (by setting up the hapi routing #2BirdsWith1Stone), then to write the functional tests, then a combination of code and unit tests ala TDD until I'm satisfied with the results.
  • CI

    • This repo also integrates TravisCI, which runs the tests defined above on every pull request, blocking a merge if the test does not pass. Not very useful for a one person project, but crucial when a team of developers is involved.

TODO

  • add stubbing framework to imitate external service calls.
  • Figure out an easy way to test multiple hapi services together, in a microservice environment.
 相关资料
  • Testing in browser Testing with NPM (CLI) Testing in browser To run the Jasmine tests in your browser, go to the following pages: <YOUR_LOCALHOST_ADDRESS>/test/E2ERunner.html - Handsontable end-to-end

  • import "testing" testing 提供对 Go 包的自动化测试的支持。通过 `go test` 命令,能够自动执行如下形式的任何函数: func TestXxx(*testing.T) 其中 Xxx 可以是任何字母数字字符串(但第一个字母不能是 [a-z]),用于识别测试例程。 在这些函数中,使用 Error, Fail 或相关方法来发出失败信号。 要编写一个新的测试套件,需要创

  • 为你的应用编写测试是一个参与的过程。Play为你提供了一个默认的测试框架,并提供了帮助器和应用存根使测试你的应用尽可能的简单。 概述 测试文件的位置在”test”文件夹中。这里有两个简单的测试文件其可以被用作为模板。 你可以从Play控制台运行测试。 点击test来按钮运行所有测试。 点击标注测试类名字比如:test-only my.namespace.MySpec的test-only按钮来运行一

  • 第一章“图层树”证实了最好使用图层相关视图,而不是创建独立的图层关系。其中一个原因就是要处理额外复杂的触摸事件。 CALayer并不关心任何响应链事件,所以不能直接处理触摸事件或者手势。但是它有一系列的方法帮你处理事件:-containsPoint:和-hitTest:。 -containsPoint:接受一个在本图层坐标系下的CGPoint,如果这个点在图层frame范围内就返回YES。如清单3

  • 每当你想要确保你的UI不会有意外的改变,快照测试是非常有用的工具。 A typical snapshot test case for a mobile app renders a UI component, takes a snapshot, then compares it to a reference snapshot file stored alongside the test. The t

  • 在本章中,我们将测试在Hello World示例章节中创建的示例项目,以演示Spring CLI的测试功能。 按照下表中列出的步骤测试示例项目 - Sr.No 步骤和说明 1 在Test文件夹中创建FirstApplication.groovy和TestFirstApplication.groovy ,如下所述。 2 编译并运行应用程序以验证实现的逻辑的结果。 FirstApplication/F