12.1. Basic issue tracking integration

http://my.jira.server/browse/MYPROJECT-{0}

To do this in Maven, you need to pass this system property to JUnit using the maven-surefire-plugin as shown here:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.7.1</version>
    <configuration>
        <systemPropertyVariables>
            <thucydides.issue.tracker.url>http://my.jira.server/browse/MYPROJECT-{0}</thucydides.issue.tracker.url>
        </systemPropertyVariables>
    </configuration>
</plugin>

Thucydides also provides special support for the Atlassian JIRA issue tracking tool. If you provide the jira.url system property instead of the thucydides.issue.tracker.url, you only need to provide the base URL for your JIRA instance, rather than the full path:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.7.1</version>
    <configuration>
        <systemPropertyVariables>
            <jira.url>http://my.jira.server</jira.url>
        </systemPropertyVariables>
    </configuration>
</plugin>

You need to provide the issue number. You can place this in the test title, prefixed by the # character. For easyb tests, this just means mentioning the issue number (always starting with a # character) somewhere in the scenario name. For JUnit tests, you use the @Title annotation as shown here:

@RunWith(ThucydidesRunner.class)
public class FixingAnIssueScenario {

    @Managed
    public WebDriver webdriver;

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

    @Steps
    public SampleScenarioSteps steps;

    @Title("Shopping cart should let users add multiple articles - fixes issues #123")
    @Test
    public void shopping_cart_should_let_users_add_multiple_articles() {
        steps.add_item_to_cart("nuts");
        steps.add_item_to_cart("bolts");
        steps.cart_should_contain("nuts","bolts");
    }
}

Another way to specify issues in JUnit is to use the @Issue or @Issues annotations. You can use the @Issue annotation to associate an individual test with a specific issue

@Issue("#123")
@Test
public void shopping_cart_should_let_users_add_multiple_articles() {
    steps.add_item_to_cart("nuts");
    steps.add_item_to_cart("bolts");
    steps.cart_should_contain("nuts","bolts");
}

You can also place the @Issue annotation at the class level, in which case the issue will be associated with every test in the class:

@RunWith(ThucydidesRunner.class)
@Issue("#123")
public class FixingAnIssueScenario {

        @Managed
        public WebDriver webdriver;

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

        @Steps
        public SampleScenarioSteps steps;

        @Test
        public void shopping_cart_should_let_users_add_multiple_articles() {
            steps.add_item_to_cart("nuts");
            steps.add_item_to_cart("bolts");
            steps.cart_should_contain("nuts","bolts");
        }

        @Test
        public void some_other_test() {
            ...
        }
}

If a test needs to be associated with several issues, you can use the @Issues annotation instead:

@Issues({"#123", "#456"})
@Test public void shopping_cart_should_let_users_add_multiple_articles() {
    steps.add_item_to_cart("nuts"); steps.add_item_to_cart("bolts");
        steps.cart_should_contain("nuts","bolts");
}

When you do this, issues will appear in the Thucydides reports with a hyperlink to the corresponding issue in your issue tracking system.

## Overriding the default reports directory

By default, Thucydides generates it’s reports in the target/site/thucydides directory. There are a couple of ways to override this, if need be. First of all, if you are overriding the default Maven output directory, you can override the <directory> element in the <build> section of your pom.xml file. However, since the Maven Surefire plugin runs the tests in a forked JVM by default, you will also need to pass in the project.build.directory property to the unit tests by using the <systemPropertyVariables> configuration element, as shown here:

     ...
    <build>
        <directory>${basedir}/build</directory>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.11</version>
                <configuration>
                    <includes>
                        <include>**/*TestScenario.java</include>
                    </includes>
                    <systemPropertyVariables>
                        <project.build.directory>${project.build.directory}</project.build.directory>
                    </systemPropertyVariables>
                </configuration>
            </plugin>
            <plugin>
                <groupId>net.thucydides.maven.plugins</groupId>
                <artifactId>maven-thucydides-plugin</artifactId>
                <version>${thucydides.version}</version>
            </plugin>
        </plugins>
    </build>

This will result in the Thucydides reports being generated in ‘build/site/thucydides` instead of `target/site/thucydides’.

If you only want to override the Thucydides output directory, you can use the thucydides.outputDirectory and thucydides.sourceDirectory properties, either in the pom.xml file, or from the commnd line. For example, the following properties will generate the Thucydides reports in the build/thucydides-reports directory:

<properties>
    <thucydides.outputDirectory>${basedir}/build/thucydides-reports</thucydides.outputDirectory>
    <thucydides.sourceDirectory>${basedir}/build/thucydides-reports</thucydides.sourceDirectory>
</properties>