Upload
wseliga
View
975
Download
0
Tags:
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
TEST JIRA PLUGINS SMARTERJIRA TestKit
Photo by kc7fys
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...
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.
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
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
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
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
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>
HOWTO - SETUP CONT.
<dependency> <groupId>com.atlassian.jira.tests</groupId> <artifactId>jira-testkit-client</artifactId> <version>${testkit.version}</version> <scope>test</scope> </dependency>
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(); // ... }
// ... }
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()); }}
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)
DON'T USE IN PRODUCTION!