Skip to content

Instantly share code, notes, and snippets.

@adamcameron
Last active September 26, 2021 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamcameron/2be808d57c70549f3e5e796216f32404 to your computer and use it in GitHub Desktop.
Save adamcameron/2be808d57c70549f3e5e796216f32404 to your computer and use it in GitHub Desktop.
TDDing a micro test framework using itself to test itself
<cfscript>
runTest("it uses a function called runTest", ()=>{})
savecontent variable="testOutput" {
runTest("runTest requires and displays a passed-in message describing the test, followed by a line break", ()=>{})
}
writeOutput(testOutput)
if (testOutput != "runTest requires and displays a passed-in message describing the test, followed by a line break<br>") {
throw(type="AssertionException", message="runTest did not output the message and line break")
}
savecontent variable="testOutput" {
runTest("runTest requires and callback which it executes", () => {
throw(type="AssertionException", message="callback was executed")
})
}
writeOutput(testOutput)
if (testOutput != "runTest requires and callback which it executes<br>callback was executed<br>") {
throw(type="AssertionException", message="callback was not executed")
}
runTest("runTest handles exceptions gracefully, reporting the exception message", () => {
throw("An exception was thrown in the callback")
})
</cfscript>
<cfscript>
function runTest(required string message, required function testCase){
writeOutput("#message#<br>")
try {
testCase()
} catch (any e) {
writeOutput("#e.message#<br>")
}
}
</cfscript>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment