Skip to content

Instantly share code, notes, and snippets.

@adamcameron
Last active Sep 26, 2021
Embed
What would you like to do?
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