Testing for Success — My presentation at Web on the Piste 2008

A couple of weeks ago, I spoke at the RIA conference Web on the Piste 2008 on the topic of “Testing for Success”.

Over the past few years, I’ve worked with many ColdFusion and Flex development teams. It has been interesting to see that there is more interest in test-driven development. However, a lot of times team leaders/company executives overlook the bigger picture and focus on just the details. And the lack of this larger context can lead to less effective/failed testing practices. My presentation this year was focused on presenting this bigger picture with focus on ColdFusion and Flex.

You can download the presentation here or view it at Slideshare.

By the way, for those of you who have not heard about Web on the Piste, it is a conference on Rich Internet Technologies that takes place every year in the beautiful Queenstown in New Zealand.

Decision Operators in ColdFusion 8

ColdFusion 8 introduced a few new decision operators.

== (is the same as EQ)

!= (is the same as NEQ)

> (is the same as GT)

< (is the same as LT)

>= (is the same as GTE)

<= (is the same as LTE)

Note that these are available only when used in expressions inside a CFScript block. And they are NOT available in expressions inside CF tags.

<cfscript>
iNum1 = 10;
iNum2 = 20;

writeOutput("<p>iNum1 = #iNum1#<br/>iNum2 = #iNum2#</p>");

/* this is same as using the EQ operator */
bResult = (iNum1 == iNum2);
writeOutput("<p>Is iNum1 equal to iNum2 (iNum1 == iNum2): #bResult#</p>");

/* this is same as using the NEQ operator */
bResult = (iNum1 != iNum2);
writeOutput("<p>Is iNum1 not equal to iNum2 (iNum1 != iNum2): #bResult#</p>");

/* this is same as using the GT operator */
bResult = (iNum1 > iNum2);
writeOutput("<p>Is iNum1 greater than iNum2 (iNum1 > iNum2): #bResult#</p>");

/* this is same as using the LT operator */
bResult = (iNum1 < iNum2);
writeOutput("<p>Is iNum1 less than iNum2 (iNum1 < iNum2): #bResult#</p>");

/* this is same as using the GTE operator */
bResult = (iNum1 >= iNum2);
writeOutput("<p>Is iNum1 greater than or equal to iNum1: (iNum1 >= iNum2): #bResult#</p>");

/* this is same as using the LTE operator */
bResult = (iNum1 <= iNum2);

writeOutput("<p>Is iNum1 less than or equal to iNum1: (iNum1 >= iNum2): #bResult#</p>");
</cfscript>

The code above produces this output.

=======Start output=======

iNum1 = 10
iNum2 = 20

Is iNum1 equal to iNum2 (iNum1 == iNum2): NO

Is iNum1 not equal to iNum2 (iNum1 != iNum2): YES

Is iNum1 greater than iNum2 (iNum1 > iNum2): NO

Is iNum1 less than iNum2 (iNum1 < iNum2): YES

Is iNum1 greater than or equal to iNum1: (iNum1 >= iNum2): NO

Is iNum1 less than or equal to iNum1: (iNum1 >= iNum2): YES

=======End output=======

More information on these can be found in the Adobe Livedocs. Note: Please also have a look at the discussion comments at the bottom of the the related blog entry Boolean Operators in ColdFusion 8.

Searching ColdFusion 8 documentation

The documentation that ships with ColdFusion 8 does not include the functionality to search — unlike ColdFusion documentation in the earlier versions which included a search.

I find that I use the documentation search quite a lot. Livedocs provides the ability to search CF 8 documentation. However, I do not necessarily want to go to the web each time I want to search.

A much nicer way to search ColdFusion 8 documentation is by using Eclipse. Here’s how…

Download CF 8 documentation for Eclipse. And then copy the JAR file into the “plugins” directory of Eclipse. Restart your Eclipse.

Go to Help > Help Contents. You should see “ColdFusion 8 Documentation” appearing in the Contents pane on the left. (If you don’t then something is wrong and you need to sort this out first.)

In the Search box on the top of the Contents pane, type in a keyword, e.g., “cfinterface”. Eclipse indexes the newly added CF Docs and shows the results.

Gotta love Eclipse.

BTW, if you use Flex Builder, you should be able to follow the same process to make CF 8 docs searchable.

String Operators in ColdFusion 8: & and &=

ColdFusion already supports string concatenation using “&” operator.

ColdFusion 8 introduces a new string operator “&=” for compound concatenation.

<cfset sFirstName = "Indy">
<cfset sLastName = "Nagpal">
<cfset spacer = " ">

<cfoutput>
variables.sFirstName = #sFirstName#<br/>
variables.sLastName = #sLastName#<br/>
variables.spacer = " "
</cfoutput>

<!--- & Concatenates strings --->
<cfset variables.sFullName = variables.sFirstName & spacer & variables.sLastName>

<p><strong>Concatanation using &</strong></p>
<p><cfoutput>#variables.sFullName#</cfoutput></p>

<!--- &= Compound concatenation. The variable on the right is used as both an element in the concatenation operation and the result variable. Thus, the expression a &= b is equivalent to a = a & b.
An expression can have only one compound assignment operator.
--->
<cfset variables.sFullName = variables.sFirstName>
<cfset variables.sFullName &= spacer>
<cfset variables.sFullName &= variables.sLastName>

<p><strong>Concatanation using &=</strong></p>
<cfoutput>#variables.sFullName#</cfoutput>

This code yields the following output.

=======Start output=======

variables.sFirstName = Indy
variables.sLastName = Nagpal
variables.spacer = ” “

Concatanation using &

Indy Nagpal

Concatanation using &=

Indy Nagpal

=======End output=======

More information on string operators in ColdFusion 8 is at Adobe ColdFusion 8 Livedocs

Boolean operators in ColdFusion 8: NOT, AND, OR

In ColdFusion 8 one can use shortcuts to refer to three boolean operators: NOT, AND, OR

NOT can also be used to as !

AND can also be used as &&

OR can also be used as ||

<cfset x = 10>
<cfset y = 30>

<cfoutput>
x = #x#<br/>
y = #y#
</cfoutput>

<!--- Reverse the value of an argument. For example, NOT True is False and vice versa. --->
<p><strong>Using NOT or !:</strong> Testing for !x eq y </p>
<cfif !x eq y>
x is not equal to y
<cfelse>
x is equal to y
</cfif>

<p><strong>Using AND or &&</strong>: Testing for x eq 10 && y eq 30</p>
<!--- Return True if both arguments are True; return False otherwise. For example, True AND True is True, but True AND False is False. --->
<cfif x eq 10 && y eq 30>
x is equal to y
<cfelse>
x is not equal to y
</cfif>

<p><strong>Using OR or ||</strong>: Testing for x eq 10 || y eq 20</p>
<!--- Return True if any of the arguments is True; return False otherwise. For example, True OR False is True, but False OR False is False. --->
<cfif x eq 10 || y eq 20>
One of the values is true
<cfelse>
None of the values are true
</cfif>

This code yields the following output.

=======Start output=======
x = 10
y = 30

Using NOT or !: Testing for !x eq y

x is not equal to y

Using AND or &&: Testing for x eq 10 && y eq 30

x is equal to y

Using OR or ||: Testing for x eq 10 || y eq 20

One of the values is true

=======End output=======

The other boolean operators — XOR, EQV, IMP — continue to work as before.
More information on boolean operators in ColdFusion 8 is at Adobe ColdFusion 8 Livedocs.