Created
October 17, 2012 09:35
-
-
Save cybersonic/3904685 to your computer and use it in GitHub Desktop.
Anatomy of a Test Case
This file contains hidden or 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
<cfcomponent extends="mxunit.framework.TestCase"> | |
<!--- this will run before every single test in this test case ---> | |
<cffunction name="setUp" returntype="void" access="public" hint="put things here that you want to run before each test"> | |
<cfset obj = createObject("component","ObjectUnderTest")> | |
</cffunction> | |
<!--- this will run after every single test in this test case ---> | |
<cffunction name="tearDown" returntype="void" access="public" hint="put things here that you want to run after each test"> | |
</cffunction> | |
<!--- this will run once after initialization and before setUp() ---> | |
<cffunction name="beforeTests" returntype="void" access="public" hint="put things here that you want to run before all tests"> | |
<cfset obj = createObject("component","ObjectUnderTest")> | |
</cffunction> | |
<!--- this will run once after all tests have been run ---> | |
<cffunction name="afterTests" returntype="void" access="public" hint="put things here that you want to run after all tests"> | |
</cffunction> | |
<!--- your test. Name it whatever you like... make it descriptive. ---> | |
<cffunction name="xxx_should_xxxx_When_xxx" returntype="void" access="public"> | |
<!--- exercise your component under test ---> | |
<cfset var result = obj.doSomething()> | |
<!--- if you want to "see" your data -- including complex variables, you can pass them to debug() and they will be available to you either in the HTML output or in the Eclipse plugin via rightclick- "Open TestCase results in browser" ---> | |
<cfset debug(result)> | |
<!--- make some assertion based on the result of exercising the component ---> | |
<cfset assertEquals("SomeExpectedValue",result,"result should've been 'SomeExpectedValue' but was #result#")> | |
</cffunction> | |
<cffunction name="xxx_should_yyy_when_zzz" returntype="void"> | |
<cfset var XX = ""> | |
<cfset fail("xxx_should_yyy_when_zzz not yet implemented")> | |
</cffunction> | |
<!--- this won't get run b/c it's private ---> | |
<cffunction name="somePrivateFunction" access="private"> | |
<cfset marc.getBankAccount().add("5 meeeeelion dollars")> | |
</cffunction> | |
</cfcomponent> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment