I've seen many SO questions around auto-generating unit tests, or documenting unit tests, but I'd like to go the reverse direction. What I'd REALLY like is to have folks (devs, tech writers, etc) write documentation with embedded code, then, as part of CI, automatically convert that documentation to runnable code, and pass/fail the pipeline based on the ability to run. The goals here would be to:
- Have more documentation driven development (where the 'T' in TDD is a test derived from the document)
- Ensure that the documentation is always up to date (because if it fails, either the code or the documentation has to be updated to pass)
- Encourage more writing of tests, particularly by folks designed to represent the users (PMs, support, etc).
So, specifically, I would like to go from something like the following (doc.md):
To use this feature, first you need to create an environment:
`
cli create environment
`
Then you need to execute the program:
`
cli program execute --arg fooz
`
This will result in the program being executed on the server.
So the idea is to go from this to an automated test that ran:
cli create environment
cli program execute --arg fooz
assert stdout == "success"
This is a pretty trivial example, but we shouldn't need more than that. We could certainly write it ourselves, but this seems like the kind of thing that would already be out there.
A more complete example that would be converted automatically and run during CI would be something like this -
https://cloud.google.com/deep-learning-vm/docs/quickstart-cli
I'm not looking for BDD or other tests that do not convert into user facing documentation, or auto generated anything (as you can see the documentation above would have to be hand written, ideally by the developer).
doctest. Also, I think your question is sending mixed signals: "I've seen many SO questions around auto-generating unit tests ... but I'd like to go the reverse direction" and then later "where the 'T' in TDD is a test derived from the document". So which way do you want to go, form tests to docs, or docs to test?