node.js - NodeJS Code Coverage of Automated Tests -


as part of custom testing framework nodejs rest api, i'd automatically detect when tests no longer providing proper coverage comparing possible outcomes test suite received.

what methods exist doing this? can assume it's being used rest api list of entry functions (api endpoints) need coverage analysis, , each entry function end known 'exit function' responds requester in standard way.

here's i've found far:

1: basic solution (currently implemented)

  • when writing each rest endpoint, manually create list of possible outcome 'codes' [success, failureduetox, failureduetoy] example
  • after tests have run, ensure every code in list has been seen test suite each endpoint.

pros: basic , easy use; doesn't change performance testing times

cons: highly prone error lots of manual checking; doesn't flag issues if there 5 ways 'failduetox' , test 1 of them. basic definition of 'coverage'

2: static analysis

  • parse code sort of parse tree , instances of 'exit function'
  • traverse tree until api endpoint reached, , add exit instance endpoint expected output (needs keep record of stack trace there via hash or similar)
  • when tests run, endpoints return stack trace hash or similar , compared expected output list.

pros: automatic; catches different branches may result in same output code

cons: generating parse tree non trivial; doesn't detect dead code never gets run; test suite needs kept in sync

3: profiling

i've done in past on embedded systems greenhills code coverage tools

  • start profiler dtrace , record stack log each test separately
  • parse stack log , assign 'test' each line of code
  • manually analyse code-with-annotations find gaps.

pros: semi automatic; gives more information total coverage developer; can see

cons: slows down tests; unable performance testing in parallel; doesn't flag when possible outcome never made happen.

what else there, , tools can me static analysis , profiling goals?

combinatorial testing (different name suggestion appreciated)

  • loosely based on idea of quickcheck
  • requires initial extraction of endpoints (and static analysis mentioned in #2), creates list of potential endpoints , arguments, , executes them
  • validation:
    • light: app shall stable handle possible inputs
    • strong: requires written specification regarding endpoints able validate against it

pros:: semi automatic (having proper tools)

cons:: specification validation tricky. i'm not aware of existing implementation.

potentially helpful node modules:


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -