I’m hoping someone can point me in the right direction for integration testing with TestKit, because I’m struggling against the lack of documentation / working examples.
In attempting to write the most basic skeleton test, I’m hitting up against a ComponentAccessor has not been initialised error, but none of the material I have found online seems to address this issue in the context of TestKit.
Could someone explain what I am supposed to do instead of the (non-functional) example below? Any help greatly appreciated!
package it;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.project.Project;
import com.atlassian.jira.testkit.client.Backdoor;
import com.atlassian.jira.testkit.client.util.TestKitLocalEnvironmentData;
import com.atlassian.jira.testkit.client.util.TimeBombLicence;
import static org.junit.Assert.assertTrue;
import java.util.Set;
import org.junit.Test;
public class LgtmServletTest {
Backdoor testKit;
public LgtmServletTest() {
testKit = new Backdoor(new TestKitLocalEnvironmentData());
testKit.restoreBlankInstance(TimeBombLicence.LICENCE_FOR_TESTING);
testKit.usersAndGroups().addUser("test-user");
testKit.project().addProject("Testing Testing", "TT", "test-user");
}
@Test
public void testCreationOfProject() {
// interact with the plugin being tested
// resulting in creation of a ticket in project TT
Project project = ComponentAccessor.getProjectManager().getProjectByCurrentKey("TT");
Set<String> issueKeys = ComponentAccessor.getIssueManager().getAllIssueKeys(project.getId());
assertTrue( 0 < issueKeys.size() );
}
}
ComponentAccessor is an internal class of Jira available inside of Jira’s JVM.
On the other hand, TeskKit is a library to perform func tests on running Jira, by calling Jira’s REST APIs. (plublic, internal or even hacky backdoors available only for tests).
So, if your goal is to write a test using testkit, you should communicate with Jira via controls provided by testkit.
Smth like
Backdoor testKit;
final Project project = testKit.project().getProject("TT");
final List<Issue> issues = node.backdoor().search().getSearch(new SearchRequest().jql("project = TT ")).issues;
etc.
Please note that testkit is limited by Jira REST APIs, so not all features from Jira Java API may be available.
Hope it helps a bit.
If not, we’ll be happy to answer other questions.
That makes a lot of sense, it certainly seemed like I was just approaching things in the wrong way.
But I think part of my confusion is that I couldn’t seem to find any get methods in TestKit, which is what I initially expected. For example testKit.project().getProject() doesn’t seem to exist?
@izinoviev Is that expected, or should that have been provided by the TestKit framework?
Also, it doesn’t seem like testKit.project().getProject() is in the latest version of TestKit. Does that mean there’s an enhanced version on the way soon…?
Also, it doesn’t seem like testKit.project().getProject() is in the latest version of TestKit. Does that mean there’s an enhanced version on the way soon…?
Yes, sorry for misinformation =)
Indeed those fancy methods exist as a part of Jira’s internal library called jira-func-tests
It seems that it should be publicly available, so I would suggest you to try it out.
It also includes com.atlassian.jira.functest.framework.BaseJiraFuncTest from which you can inherit your tests. Then you’ll be able to use fancy methods in your tests =)