Hello!
There are three ways to write integration tests in Jira:
1. Wired tests - these tests can check if your exported services in your plugin work correctly.
2. Integration tests written with the help of jira-func-test-plugin and jira-testkit-plugin -
these tests check the web-UI of your plugin, using HTTP requests and responses to assert that the web-UI is exhibiting the correct behaviour.
3. Page objects tests - these tests also check the web-Ui by using HTTP requests and responses but with the Selenium web driver under the hood.
As it is written by Atlassian the third way is more preferable than the second way. But in this article we will try to create integration tests with the second way: integration tests with the jira-func-test-plugin and jira-testkit-plugin.
The source code of the plugin in this article you can find here.
The main difference of an integration test from a unit test is that an integration test runs on a Jira instance, while a unit test runs without an available Jira instance.
That is why we need a Jira instance to be up to run our tests. It is not required to run a Jira instance from the same plugin, where your integration tests are. You can run integration tests on a remote instance of Jira. But first we will run our tests on a Jira instance from the same plugin, where the integration tests are. Later we will see, how to run the same tests on a remote instance.
You create a Jira plugin with the atlas-create-jira-plugin command.
You should add the following dependencies to your plugin:
<dependency>
<groupId>com.atlassian.jira.tests</groupId>
<artifactId>jira-testkit-client</artifactId>
<version>${jira.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-func-tests</artifactId>
<version>${jira.version}</version>
<scope>test</scope>
</dependency>
These dependencies will let you write integration tests in your plugin.
There should be the jira-func-test-plugin and jira-testkit-plugin plugins installed in the Jira instance, which is going to be under tests, otherwise integration tests will not work. That is why we should add the following plugins to the pom.xml file into the configuration section of the maven-jira-plugin:
<pluginArtifacts>
<pluginArtifact>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-func-test-plugin</artifactId>
<version>${jira.version}</version>
</pluginArtifact>
<pluginArtifact>
<groupId>com.atlassian.jira.tests</groupId>
<artifactId>jira-testkit-plugin</artifactId>
<version>7.12.3</version>
</pluginArtifact>
</pluginArtifacts>
Let's create the ExampleTest.java file in the src/test/java/it/ru/matveev/alexey/jira/integrationtests/selenium/ folder:
package it.ru.matveev.alexey.jira.integrationtests.selenium;
import com.atlassian.jira.functest.framework.BaseJiraFuncTest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class ExampleTest extends BaseJiraFuncTest {
@Before
public void setup() {
backdoor.project().addProject("testproject", "TP", "admin");
backdoor.issues().createIssue("TP", "test issue");
}
@Test
public void goToIssueNavigator() {
navigation.login("admin");
navigation.issueNavigator().createSearch("project = TP");
tester.assertTextPresent("TP-1");
}
@After
public void cleanup() {
backdoor.project().deleteProject("TP");
}
By default any test must have the Test suffix in the class name so that it could be run as a test.
This behaviour can be changed if we provide the functionalTestPattern parameter for the configuration part of the maven-jira-plugin.
In this test we want to check that the search in the Issue Navigator works. That is why in the setup method we create a project and an issue in this project. Then we create a query to select the created issue and check that the created issue were selected.Then in the cleanup method we delete our project.
Now we can run this test with the atlas-integration-test command. It will start a Jira instance and execute our test.
There are a couple of classes from which your test class must be extended: BaseJiraEmailTest, BaseJiraFuncTest, BaseJiraRestTest. The most used class is the BaseJiraFuncTest. This class allows to test you any functionality in Jira.
This class has the following variables, which you can use in your test class:
backdoor - allows you to perform administrative functions in Jira like managing projects, indexes, permission schemes, users and so on.
navigation - lets you navigate to different screens in your Jira. Also it lets you login to Jira and logout.
tester - lets you work with pages in Jira: set values for custom fields, click buttons, check if an element is present and so on.
It is important to know that the integration test engine tries to connect to Jira under the admin user with the password admin. Also when you use the navigation.login('username") to login to Jira. The password of the user must be equal to the username.
You should install the jira-func-test-plugin and jira-testkit-plugin to the remote instance and set parameters of your remote instance in the src/test/resources/localtest.properties file:
jira.protocol = http
jira.host = remote-instance
jira.port = 2991
jira.context = /jira
jira.edition = all
jira.xml.data.location = src/test/xml
Now you can run the atlas-integration-test command and your tests will be run on the remote instance.
And the best part is that the developers of the jira-func-tests package inserted there many examples on how to write tests. You can find them in the webtests package.
That is all for tests. Hopefully this info was useful to you. Good luck with Jira testing!
Alexey Matveev
software developer
MagicButtonLabs
Philippines
1,574 accepted answers
6 comments