13
TEST JIRA PLUGINS SMARTER JIRA TestKit Photo by kc7fys

AtlasCamp 2012 - Testing JIRA plugins smarter with TestKit

  • Upload
    wseliga

  • View
    975

  • Download
    0

Embed Size (px)

DESCRIPTION

Slides from my lightning talk presented at AltasCamp 2012 about a hot new testing library useful for testing functionality of JIRA plugins.

Citation preview

Page 1: AtlasCamp 2012 - Testing JIRA plugins smarter with TestKit

TEST JIRA PLUGINS SMARTERJIRA TestKit

Photo by kc7fys

Page 2: AtlasCamp 2012 - Testing JIRA plugins smarter with TestKit

ORIGINAL PROBLEMS

• a lot of functional tests - their execution is really time consuming (JIRA CI env uses 60+ remote agents and builds still may take hours)

• opaque test fixtures - tons of XML dumps difficult to maintain

• most of time spent by JWebUnit/HtmlUnit/Selenium/WebDriver in UI not under test

• JUnit 3.x is 12 years old...

Page 3: AtlasCamp 2012 - Testing JIRA plugins smarter with TestKit

PROBLEM AMPLIFICATION

• With WebDriver and PageObjects writing functional tests got too easy (at least superficially) and the number of them exploded

• JIRA is now developed by multiple teams and consists of bundled plugins built and tested separately, but ... jira-func-tests were not easily reusable easily outside JIRA core src tree - especially against various JIRA versions.

Page 4: AtlasCamp 2012 - Testing JIRA plugins smarter with TestKit

THE SOLUTION: REST-DRIVEN TEST FIXTURES AND ASSERTIONS

• order of magnitude faster than driven by UI

• less fragile (races, changes in UI)

• clear and readable test fixture set-ups (no more opaque XML dumps)

• stricter, more powerful and less fragile assertions

Page 5: AtlasCamp 2012 - Testing JIRA plugins smarter with TestKit

JIRA REST API

• Awesome (as of JIRA 5.0), but ... still limited

• Almost non-existent for administrative operations

• Use whenever you can

• JRJC (JIRA REST Java Client) makes using REST API from Java very easy

Page 6: AtlasCamp 2012 - Testing JIRA plugins smarter with TestKit

BACKDOOR

• Unofficial dev-only JIRA REST API providing missing functionalities

• Originally part of JIRA source tree (unavailable for mortals)

• Very easy to extend and consume: very lightweight lifecycle, no need to care too much about long-term commitments, security, ideal shape of representations, HTTP return codes, etc.

• Comes with *Control classes, which allow to easily do remote calls from Java

Page 7: AtlasCamp 2012 - Testing JIRA plugins smarter with TestKit

JIRA TESTKIT

• Backdoor for the Ecosystem

• Consists of two parts:

• JIRA Plugin deployed only during tests and exposing additional REST resources

• Java client library talking remotely to JIRA and using these additional REST resources

• We hope promote most useful resources from Backdoor to the official JIRA REST API

Page 8: AtlasCamp 2012 - Testing JIRA plugins smarter with TestKit

HOW TO - SETUP

<plugin> <groupId>com.atlassian.maven.plugins</groupId> <artifactId>maven-jira-plugin</artifactId> <configuration> <pluginArtifacts> <pluginArtifact> <groupId>com.atlassian.jira.tests</groupId> <artifactId>jira-testkit-plugin</artifactId> <version>${testkit.version}</version> </pluginArtifact> </pluginArtifacts> </configuration> <plugin>

Page 9: AtlasCamp 2012 - Testing JIRA plugins smarter with TestKit

HOWTO - SETUP CONT.

<dependency> <groupId>com.atlassian.jira.tests</groupId> <artifactId>jira-testkit-client</artifactId> <version>${testkit.version}</version> <scope>test</scope> </dependency>

Page 10: AtlasCamp 2012 - Testing JIRA plugins smarter with TestKit

HOWTO - USING IN TESTpublic class MyPluginTest extends FuncTestCase {

@Override protected void setUpTest() { super.setUpTest(); Backdoor testKit = new Backdoor(

new TestKitLocalEnvironmentData()); testKit.restoreBlankInstance(

TimeBombLicence.LICENCE_FOR_TESTING); testKit.usersAndGroups().addUser("test-user"); testKit.websudo().disable(); testKit.subtask().enable(); // ... }

// ... }

Page 11: AtlasCamp 2012 - Testing JIRA plugins smarter with TestKit

public class TestBugzillaImporter extends TestBase {

private JiraRestClient restClient;

@Before public void setUpTest() { backdoor().restoreBlankInstance(); backdoor().attachments().enable(); backdoor().timeTracking().enable("8", "5", TimeTracking.Format.PRETTY,

TimeTracking.Unit.HOUR, TimeTracking.Mode.MODERN); restClient = ITUtils.createRestClient(jira().environmentData()); }

@Test public void someTest() { // execute your test using Page Objects / WebDriver // ... // maybe you need some special license assertTrue(backdoor().license().switchToPersonalLicense()); // ...

// maybe it should create a user and put it into an appropriate group assertTrue(backdoor().usersAndGroups().userExists("mytestuser")); assertTrue(backdoor().usersAndGroups().isUserInGroup("mytestuser", "jira-users")); // maybe it creates a JIRA issue final Issue issue = restClient.getIssueClient().getIssue("TES-19",

new NullProgressMonitor()); assertEquals("expectedreporter", issue.getReporter().getName()); assertEquals("expectedassignee", issue.getAssignee().getName()); }}

Page 12: AtlasCamp 2012 - Testing JIRA plugins smarter with TestKit

HOW CAN I USE IT

• It's hot and bleeding edge, still changing shape (right as I am speaking)

• https://developer.atlassian.com/display/JIRADEV/Plugin+Tutorial+-+Smarter+integration+testing+with+TestKit

• https://bitbucket.org/atlassian/jira-testkit/ (planning to open-source it)

• https://bitbucket.org/atlassian/jira-testkit-example

• https://marketplace.atlassian.com/plugins/com.atlassian.jira.tests.jira-testkit-plugin

• JIRA Importers Plugin source code (bundled with JIRA src distro)

Page 13: AtlasCamp 2012 - Testing JIRA plugins smarter with TestKit

DON'T USE IN PRODUCTION!