2016-07-05 4 views
1

필자는 자동화 된 API 문서 세대 인 Spring Boot 자바 프레임 워크로 프로젝트 작업을했습니다. BDD/통합 스타일 테스트를 실행할 때마다 mocha 테스트에서 작성된 api 파란색 프린트 파일이 있습니다. 그런 다음 generate-html-from-api 청사진을 실행했습니다. 나는이 접근법이 두 가지 장점을 가지고 있기 때문에 좋아했다.모카 BDD 테스트에서 API html 문서를 생성하는 방법은 무엇입니까?

1) API docs are always correct and up-to-date 
2) saves time, because no need to write another documentation file (like apidoc). 

누구나 노드 프로젝트에 대한 예제를 시도 했습니까? 나는 api-doc-test 플러그인을 발견했지만 문서는 제한적입니다. ? 이상적으로는 다음을 실행하고 싶습니다.

mocha --recursive 

그러면 test/tmp /가 생성됩니다.

나는 두들겨 봤지만 실제로 두 번 끝점 정보를 지정하고 싶지 않으며 BDD 테스트에서 한 번만 쓰고 동시에 두 번 결과 (테스트 + 워드 프로세서)를 갖게됩니다.

+0

FWIW 우리가 만들지 않은 API의 청사진에서 발생합니다. 대신 우리는 API가 무엇인지에 대한 검증 가능한 계약이되도록 구축했습니다. 그래서 https://github.com/apiaryio/dredd를 구축하여 계약 (API Blueprint)에 맞게 구현을 테스트 할 수 있습니다./나는 API Blueprint/ – Zdenek

+0

@ Zdenek의 저자입니다. 감사합니다. 내 그림이 바뀝니다. 소규모 시작의 경우 한 가지 유형의 테스트 만 작성해야합니다. 그렇지 않으면 너무 비쌉니다. 따라서 모카를 사용하는 대신 API blueprint + Dredd를 사용하여 전체 BDD/통합 테스트를 작성할 수 있습니까? – Centurion

+0

시나리오에 만족하면 충분합니다 (외부로부터 판단하기가 어렵습니다) – Zdenek

답변

0

https://github.com/stackia/test2doc.js

나는 당신이 필요로하는 바로 정확하게 생성 문서 BDD 시험에서 (현재는 API 청사진)을 가능하게이 프로젝트에 일하고 있어요.

테스트 코드 예제 :

const doc = require('test2doc') 
const request = require('supertest') // We use supertest as the HTTP request library 
require('should') // and use should as the assertion library 

// For Koa, you should exports app.listen() or app.callback() in your app entry 
const app = require('./my-express-app.js') 

after(function() { 
    doc.emit('api-documentation.apib') 
}) 

doc.group('Products').is(doc => { 
    describe('#Products', function() { 
    doc.action('Get all products').is(doc => { 
     it('should get all products', function() { 
     // Write specs towards your API endpoint as you would normally do 
     // Just decorate with some utility methods 
     return request(app) 
      .get(doc.get('/products')) 
      .query(doc.query({ 
      minPrice: doc.val(10, 'Only products of which price >= this value should be returned') 
      })) 
      .expect(200) 
      .then(res => { 
      body = doc.resBody(res.body) 
      body.desc('List of all products') 
       .should.not.be.empty() 
      body[0].should.have.properties('id', 'name', 'price') 
      body[0].price.desc('Price of this product').should.be.a.Number 
      }) 
     }) 
    }) 
    }) 
}) 
관련 문제