TDDing a micro test framework using itself to test itself
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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