Functional Testing with Twist

Twist is an automated functional testing framework from ThoughtWorks Studios. I am used to using FitNesse so I am interested in seeing how the two products compare.

Writing your first real FitNesse test can be tricky business, which fixture should I use, where does my wiki mark up go, how is my wiki markup different depending on which fixture type I choose etc etc. Using Twist I found that it took only about 10 minutes to write and execute my first fixture, scenario in Twist language and this is what was involved :

  • Create a new project

CreateNewTwistProject

  • Create a new scenario and call it something like ‘When searching for Twist on Google’
  • Using the intellisense sortcut in elclipse, ctrl+space, Twist gives you the option of adding a new ‘Business Scenario’ . Select this option and name the scenario ‘Should display the link to the twist home page’.

To define the steps that Twist should carry out you write a bulleted list of actions, here is my example:

NewWorkflow

At this point you can execute the scenario, click on the execute button in the top right of the screen, the test will run but will fail. The error message is “java.lang.Exception: Context “New Context” is not implemented”, cryptically, this is telling me that I have to go and implement the java that will execute this workflow.

The context contains the setup and tear down code for the test, to create this click on the at the top.

import com.thoughtworks.twist.driver.selenium.TwistSelenium;

public class NewContext {

	private TwistSelenium selenium;

	public NewContext(TwistSelenium selenium) {
		this.selenium = selenium;
	}

	public void setUp() throws Exception {
		selenium.open("http://www.google.co.uk");
	}

	public void tearDown() throws Exception {
		selenium.close();
	}
}

Run the scenario again and you will get the following exception ‘java.lang.Exception: Workflow step “Enter text “Twist”” is not implemented’. This is telling you to create a method called ‘enterText’. To implement this you can click on the workflow item and use ctrl+space again this will give you an option to generate a stub class with the correct name. You can create the method ‘enterText’ by clicking on the ‘Enter text “Twist”‘ workflow item and using ctrl+space this will again give you an option of creating the method stub with the correct name, implement the method and re-run the test.

Re-running the test will give you another exception, not surprisingly, telling me that the clickOn method is not declared, so I implement that and the last method, assertThatExistsOnThePage, and run the test one more time. Hoooray, it passes, I can see IE start up and selenium running through my scenario. Cool stuff.

Here is the code I finished up with:

// JUnit Assert framework can be used for verification

import com.thoughtworks.twist.driver.selenium.TwistSelenium;

public class ShouldFindThoughtWorksInTheSearchResults {

	private TwistSelenium selenium;

	public ShouldFindThoughtWorksInTheSearchResults(TwistSelenium selenium) {
		this.selenium = selenium;
	}

	public void enterText(String text) throws Exception {
		selenium.type("q", text);
	}

	public void clickOn(String identifier) throws Exception {
		selenium.click(identifier);
	}

	public void assertThatExistsOnThePage(String text) throws Exception {
		assertThatExistsOnThePage(text);
	}
}

Aside: Another nice feature of Twist, is it has tight integration with a unit testing framework, jUnit, which I can leverage to implement my assertions, FitNesse does not give you this tight integration.

Another aside: I am sure you have worked this out but the correlation between the steps in the business workflow and the methods that are created in java is as follows. Each step in the business workflow represents a method call, the methods are named by concatenating the words that are not in quotes and applying camelCasing, the words that are in quotes are the parameters that the method takes and are passed to the method in the order they appear. This is quite similar to the Do fixture in FitNesse.

Twist has an integrated environment for writing your tests, it is built ontop of elclipse, which is something that FitNesse lacks, it also doesn’t require you to learn any wiki markup to specify your scenarios. For me this is more of a benifit, whilst you are getting over the initial learning curve, as you become more proficient this is likley to be less important.

I use FitNesse for testing subsystems, things like individual services and for end-to-end testing, obviously for testing the whole system. The immediate disadvantage with Twist is that I can’t use it for subsystem testing. Twist has been designed to sit on-top of tools like selenium and Frankenstein which drive the UI. Additionally I predominatly work in a .Net environment, FitNesse provides a .Net adaptor to allow me to get into the code and configure and host my services, Twist doesn’t provide that level of support for anything that is not written in Java. An obvious downside to Twist vs FitNesse is that it is a paid for product.

I have used Twist to add tests here to add tests to an existing system, I see no reason why you couldn’t use this to specify your system as well before it has been created.

After only a brief encounter with Twist I’m not sure if it is as flexible or mature as FitNesse but it looks like a nice product to use and I can definatly see that it has its place. I have definatly got some more questions regarding Twist so will be spending some more time figuring out what is possible with it. It would also seem to be lacking one key feature which is integration with Mingle, without this you are going to have to maintain 2 separate sets of requirements.

You can download a trial version of Twist from: ThoughtWorks Studios.

Advertisements

~ by Tim on 3 October 2009.

5 Responses to “Functional Testing with Twist”

  1. Twist has been designed keeping in mind the ideas behind the FIT/FITnesse set of tools.

    We’re trying hard to ensure that there is enough of tooling support to provide quicker feedback while editing without having to execute tests.

    Glad that you like Twist.

    Keep twisting!

    — Ketan
    Developer in Twist

  2. I forgot to mention that you may feel free to ask any questions on the Twist community site and we’ll be glad to respond.

    Also expect better and tighter mingle integration in future releases 🙂

    — Ketan

  3. Hi Tim,

    Twist is something I have been meaning to look at for a while along with many other acceptance testing toolkits/frameworks so was good to see a write up on it. Keep blogging! 🙂

  4. Hello guys
    How can you guys even compare this paid eclipse plugin to a opensource library like fit/fitnesse?
    Fitnesse is 100 times much better than twist.
    Twist is just a bunch of heavy monster jars(no dependency management and all spring stuff are jarred in single jar) which gets added to your classpath on eclipse.why should I pay for an eclipse plugin?afterall if I use selenium2 with twist than what am I getting out of twist?just an IDE to refactor my scenario file?
    How many fixtures does twist support?they just cooed the idea of row fixture from fitness.and what else after that?am I missing anything from twist here?oh not to mention that there is no horizontal scroll bar in that broken eclipse plugin.good luck you twisters:)
    It’s just my opinion.please educate me so that I will know about many more functioanlites of twist

  5. suman is right.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

 
%d bloggers like this: