Skip to main content

Thucydides Release 0.4.15 - two-way JIRA integration

Posted by johnsmart on October 21, 2011 at 3:05 PM PDT

A new version of Thucydides is out - version 0.4.15 - with some exciting new features, updates and improvements. Thucydides is a library designed to make it easier to write automated acceptance criteria on top of WebDriver/Selenium 2 (see this article for a general introduction).

An overview of the highlights of this release are presented here:

  • Two-way integration with JIRA, including support for custom workflows
  • Better support for parallel testing in JUnit and easyb
  • This version uses Selenium 2.9.0
  • Easyb integration uses the latest version of easyb (1.4) from Maven Central (no messy custom repository configuration required)

In the rest of this article, we will concentrate how you can integrate JIRA with your automated acceptance tests using Thucydides.

When you are using Thucydides with JUnit or easyb, tests or scenarios can implement acceptance criteria for particular user stories. A common strategy for organizations using JIRA is to represent story cards, and/or the associated acceptance criteria, as JIRA issues.

To set up JIRA integration with Thucydides, you need to add the thucydides-jira-plugin to your Maven dependencies. The dependencies you will need (including the normal Thucydides ones) are listed here:

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-all</artifactId>
        <version>1.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>net.thucydides</groupId>
        <artifactId>thucydides-junit</artifactId>
        <version>0.4.15</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>net.thucydides.easyb</groupId>
        <artifactId>thucydides-easyb-plugin</artifactId>
        <version>0.4.15</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>net.thucydides.plugins.jira</groupId>
        <artifactId>thucydides-jira-plugin</artifactId>
        <version>0.5.4</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.codehaus.groovy</groupId>
        <artifactId>groovy-all</artifactId>
        <version>1.8.2</version>
    </dependency>        
    ...

Note that the JIRA workflow integration needs Groovy 1.8 or higher to work properly.

You will also need an slf4j implementation, e.g. 'slf4j-log4j12' (if you are using Log4j) or 'logback-classic' (if you are using LogBack) (see here for more details). If you're stuck, just add slf4j-simple:

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
        <version>1.6.1</version>
    </dependency>

In Thucydides, you can refer to a JIRA issue by placing a reference to the corresponding JIRA issue number either in the name of the test (using the @Title annotation, for example), or, more simply, by using the @Issue or @Issues annotation as shown here:

    @RunWith(ThucydidesRunner.class)
    public class SearchByKeywordStoryTest {

        @Managed(uniqueSession = true)
        public WebDriver webdriver;

        @ManagedPages(defaultUrl = "http://www.wikipedia.com")
        public Pages pages;

        @Steps
        public EndUserSteps endUser;

        @Issue("#WIKI-1")
        @Test
        public void searching_by_unambiguious_keyword_should_display_the_corresponding_article() {
            endUser.is_on_the_wikipedia_home_page();
            endUser.looks_up_cats();
            endUser.should_see_article_with_title("Cat - Wikipedia, the free encyclopedia");

        }
    }

In this example, the test will be associated with issue WIKI-1.

Alternatively, you may want to associate an issue (such as a story card) with all of the stories in a test case by placing the @Issue (or @Issues) annotation at the class level:

 
        @RunWith(ThucydidesRunner.class)
        @Issue("#WIKI-1")
        public class SearchByKeywordStoryTest {

            @Managed(uniqueSession = true)
            public WebDriver webdriver;
           
            @ManagedPages(defaultUrl = "http://www.wikipedia.com")
            public Pages pages;

            @Steps
            public EndUserSteps endUser;

            @Test
            public void searching_by_unambiguious_keyword_should_display_the_corresponding_article() {
                endUser.is_on_the_wikipedia_home_page();
                endUser.looks_up_cats();
                endUser.should_see_article_with_title("Cat - Wikipedia, the free encyclopedia");

            }
        }

Thucydides can use these annotations to integrate with the issues in JIRA. The most simple JIRA integration involves adding links to the corresponding JIRA issues in the Thucydides reports. To activate this, you simply need to provide the *jira.url* command line option. You do however need to pass this option to JUnit using the maven-surefire-plugin, as shown here:

 
  <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.10</version>
            <configuration>
                <argLine>-Xmx1024m</argLine>
                <systemPropertyVariables>                             
                    <jira.url>http://jira.acme.com</jira.url>                              
                </systemPropertyVariables>    
            </configuration>
        </plugin>
        ...

For tighter, round-trip integration you can also use thucydides-jira-plugin. This will not only include links to JIRA
in the Thucydides reports, but it will also update the corresponding JIRA issues with links to the corresponding
Story page in the Thucydides reports. To set this up, add the thucydides-jira-plugin dependency to your project
dependencies:

    <dependency>
        <groupId>net.thucydides.plugins.jira</groupId>
        <artifactId>thucydides-jira-plugin</artifactId>
        <version>0.5.4</version>
        <scope>test</scope>
    </dependency>   

You also need to provide a username and password to connect to JIRA, and the URL where your Thucydides reports will be published (for example, on your CI server). You do using by passing in the jira.username, jira.password and thucydides.public.url system parameters.
 
  <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.10</version>
            <configuration>
                <argLine>-Xmx1024m</argLine>
                <systemPropertyVariables>                             
                    <jira.url>http://jira.acme.com</jira.url>                              
                    <jira.username>${jira.demo.user}</jira.username>
                    <jira.password>${jira.demo.password}</jira.password>
                    <thucydides.public.url>http://localhost:9000</thucydides.public.url>
                </systemPropertyVariables>    
            </configuration>
        </plugin>
        ...

Thucydides also generates aggregate reports grouping results for stories and features. To include the JIRA links in these reports as well, you need to set the jiraUrl configuration option in the
maven-thucydides-plugin, as illustrated here:

        
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-site-plugin</artifactId>
        <version>3.0-beta-3</version>
        <configuration>
            <reportPlugins>
                <plugin>
                    <groupId>net.thucydides.maven.plugins</groupId>
                    <artifactId>maven-thucydides-plugin</artifactId>
                    <version>@project.version@</version>
                    <configuration>
                         <jiraUrl>http://jira.acme.com</jiraUrl>             
                     </configuration>
                 </plugin>
            </reportPlugins>
        </configuration>
    </plugin>        

If you do not want Thucydides to update the JIRA issues for a particular run (e.g. for testing or debugging purposes), you can also set thucydides.skip.jira.updates to true, e.g.

    $mvn verify -Dthucydides.skip.jira.updates=true

You can also configure the plugin to update the status of JIRA issues. This is deactivated by default: to use this
option, you need to set the thucydides.jira.workflow.active option to 'true', e.g.

 
    $mvn verify -Dthucydides.jira.workflow.active=true

The default configuration will work with the default JIRA workflow: open or in progress issues associated with successful tests will be resolved, and closed or resolved issues associated with failing tests will be reopened. If you are using a customized workflow, or want to modify the way the transitions work, you can write your own workflow configuration. Workflow configuration uses a simple Groovy DSL. The following is an example of the configuration file used for the default workflow:

 
    when 'Open', {
        'success' should: 'Resolve Issue'
    }

    when 'Reopened', {
        'success' should: 'Resolve Issue'
    }

    when 'Resolved', {
        'failure' should: 'Reopen Issue'
    }

    when 'In Progress', {
        'success' should: ['Stop Progress','Resolve Issue']
    }

    when 'Closed', {
        'failure' should: 'Reopen Issue'
    }

You can write your own configuration file and place it on the classpath of your test project (e.g. in the src/test/resources directory). Then you can override the default configuration by using the thucydides.jira.workflow property in the Maven pom.xml file or directly on the command line e.g.

 
    $mvn verify -Dthucydides.jira.workflow=my-workflow.groovy

Alternatively, you can simply create a file called and place it somewhere on your classpath. Thucydides will then use this workflow. In both these cases, you don't need to explicitly set the thucydides.jira.workflow.active property.

You can also integrate JIRA issues into your easyb Thucydides stories. When using the Thucydides easyb integration, you associate one or more issues with the easyb story as a whole, but not with the individual scenarios. You do this using the thucydides.tests_issue notation:

 
    using "thucydides"

    thucydides.uses_default_base_url "http://www.wikipedia.com"
    thucydides.uses_steps_from EndUserSteps
    thucydides.tests_story SearchByKeyword

    thucydides.tests_issue "#WIKI-2"

    scenario "Searching for cats", {
        given "the user is on the home page", {
            end_user.is_on_the_wikipedia_home_page()
        }
        when "the end user searches for 'cats'", {
            end_user.looks_up_cats()
        }
        then "they should see the corresponding article", {
           end_user.should_see_article_with_title("Cat - Wikipedia, the free encyclopedia")
        }
    }  

You can also associate several issues using thucydides.tests_issues:

                                 
    thucydides.tests_issue "#WIKI-2", "#WIKI-3"

To use easyb with Thucydides, you need to add the latest version of thucydides-easyb-plugin to your dependencies if it is not already there:

     
    <dependency>
        <groupId>net.thucydides.easyb</groupId>
        <artifactId>thucydides-easyb-plugin</artifactId>
        <version>0.4.15</version>
        <scope>test</scope>
    </dependency>

As with JUnit, you will need to pass in the proper parameters to easyb for this to work. You will also need to be using the maven-easyb-plugin version 1.3 or higher, configured to pass in the JIRA parameters as shown here:

 
        <plugin>
        <groupId>org.easyb</groupId>
        <artifactId>maven-easyb-plugin</artifactId>
        <version>1.3</version>
        <executions>
            <execution>
                <goals>
                    <goal>test</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <storyType>html</storyType>
            <storyReport>target/easyb/easyb.html</storyReport>
            <easybTestDirectory>src/test/stories</easybTestDirectory>
            <parallel>true</parallel>
            <jvmArguments>
                <jira.url>http://jira.acme.com</jira.url>                              
                <jira.username>${jira.demo.user}</jira.username>
                <jira.password>${jira.demo.password}</jira.password>
                <thucydides.public.url>http://localhost:9000</thucydides.public.url>
            </systemPropertyVariables>    
            </jvmArguments>
        </configuration>
    </plugin>

Once this is done, Thucydides will update the relevant JIRA issues automatically whenever the tests are executed.

Related Topics >>