Auto rewrite unit tests [2018-06-11 Mon 19:33]

Suggest

Can unit tests be reduced to a form where machines can rewrite them automatically? A first approach might be diff'ing the parse trees between the (current AST) and (AST previous commit). Then using the diff to produce an automatic translation from (AST of tests from previous commit) to the current commit.

This must be possible, maybe not with current tools, but people do it manually all the time and it's generally regarded as one of the more mundane tasks. Tests usually contain just enough state to test one function or method, it's a very constrained use of the library under test's API, so code with the least possible complexity to demonstrate soundness.

Maybe building abstractions over the API usage itself, to describe how it is used, a generalized test protocol. Bonus, something like this could generate documentation.

AutoProtocols

TestProtocolFoo

  • construct datatype
  • assert pre conditions
  • test property
  • assert post conditions

TestProtocolBarDB

  • init database
  • assert pre conditions
  • commit data
  • HTTP POST
  • assert post conditions

Author: Derek Rhodes

Created: 2018-07-29 Sun 22:12

Validate