Concordion ATDD | Spec driven development

Concordion ATDD Framework

Quick Notes on Concordion Acceptance Test Driven Development Testing.

Thumb Rule is that a concordion test class can be run just like a JUnit class and hence for all the code that can be covered by JUnit, we can have spec HTML built and tested with concordion. Concordion uses the HTML <span> attribute that embeds within the spec HTML without altering its appearance.

1) concordion:set

2)  concordion:assertEquals

Test Spec:

When user World logs in, the greeting will be: Hello World!

Test HTML:

<p>
When user <b concordion:set=”#firstName>World</b> logs in, the
greeting will be: <span concordion:assertEquals=”greetingFor(#firstName)”>Hello World!</span>
</p>

Test Code:
public class HelloWorldTest extends ConcordionTestCase {
public String greetingFor(String firstName) {
return new Greeter().greetingFor(firstName);
}
}

3) concordion:execute
3 Uses :
Executing an instruction with a “void” result.
Executing an instruction with an object result (to allow multiple properties of the object to be checked).
Handling unusual sentence structures.

Spec HTML :

If the time is
09:00AM
then the greeting will say:
Good Morning World!

We can also use a special variable #TEXT (which contains the text of the current element)

=====================================================================================

Concordion Spec Example and Code to make a test pass:

For the provided spec :

After a user logs into the system, a greeting is displayed
saying “Hello [user’s first name]!” And User is greeted according to
the time of the day.

ExampleWhen user Rahul logs in, the
greeting will be: Hello Rahul!If time is between
Period Start Time Period End Time  Greeting to the User
12:00AM 1:00PM Good Morning!
1:00PM 5:00PM Good Afternoon!
5:00PM 12:00AM Good Night!

The java code for the spec:

package com.example.specs.greeting;

import org.concordion.integration.junit3.ConcordionTestCase;

import com.example.Greeter;

public class HelloWorldTest extends ConcordionTestCase {

public String greetingFor(String firstName) {
return new Greeter().greetingFor(firstName);
}

public String greetingStringByTimeInterval(String timeStart, String timeEnd){
return greetingByTimeOfDay(timeStart, timeEnd);
}

private String greetingByTimeOfDay(String timeStart, String timeEnd) {

// Just input string params compared. In  a more realistic scenario, date objects to be used.
String resultGreeting = “”;
if(“12:00AM”.equalsIgnoreCase(timeStart) && “1:00PM”.equalsIgnoreCase(timeEnd)){
resultGreeting = “Good Morning!”;
}else if(“1:00PM”.equalsIgnoreCase(timeStart) && “5:00PM”.equalsIgnoreCase(timeEnd)){
resultGreeting = “Good Afternoon!”;
}else if(“5:00PM”.equalsIgnoreCase(timeStart) && “12:00AM”.equalsIgnoreCase(timeEnd)){
resultGreeting = “Good Night!”;
}
return resultGreeting;
}

}

=====================================================================================
Adding Concordian as a Maven Dependency:

mvn install:install-file -DgroupId=org.concordion -DartifactId=concordion
-Dversion=1.4.2 -Dpackaging=jar -Dfile=concordion-1.4.2.jar

in pom.xml:

<dependency>
<groupId>org.concordion</groupId>
<artifactId>concordion</artifactId>
<version>1.4.2</version>
<scope>test</scope>
</dependency>
<dependency>

<!– xom parser is used by concordion to parse the concordion test html –>
<groupId>xom</groupId>
<artifactId>xom</artifactId>
<version>1.1d2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ognl</groupId>
<artifactId>ognl</artifactId>
<version>2.7.2</version>
<scope>test</scope>
</dependency>

Using the Maven Surefire Plugin (as it will handle Concordion , just like it runs JUnit tests)

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemProperties>
<property>
<name>concordion.output.dir</name>
<value>target/concordion</value>
</property>
</systemProperties>
</configuration>
</plugin>

#test-driven-development