I am creating integration tests for a Jira plugin. I am using atlassian-plugin-sdk-3.8 (that targets Jira version 4.4.1).
The tests fail when they try to use ComponentAccessor functionality, with this stack trace:
-------------------------------------------------------------------------------
Test set: it.com.epelo.jiraplugins.loaders.JiraProjectHandlerTest
-------------------------------------------------------------------------------
Tests run: 3, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 96.595 sec <<< FAILURE!
testCreateProjectExists(it.com.epelo.jiraplugins.loaders.JiraProjectHandlerTest) Time elapsed: 6.403 sec <<< ERROR!
java.lang.IllegalStateException: ComponentAccessor has not been initialised.
at com.atlassian.jira.component.ComponentAccessor.getWorker(ComponentAccessor.java:816)
at com.atlassian.jira.component.ComponentAccessor.getComponentOfType(ComponentAccessor.java:109)
at com.atlassian.jira.component.ComponentAccessor.getProjectManager(ComponentAccessor.java:114)
at it.com.epelo.jiraplugins.loaders.JiraProjectHandlerTest.testGetProjectManager(JiraProjectHandlerTest.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:168)
at com.atlassian.jira.functest.framework.FuncTestCase.runTest(FuncTestCase.java:266)
at junit.framework.TestCase.runBare(TestCase.java:134)
at com.atlassian.jira.functest.framework.FuncTestCase.runBare(FuncTestCase.java:300)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:91)
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:62)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:140)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:127)
at org.apache.maven.surefire.Surefire.run(Surefire.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:345)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1009)
The failure is caused by this test:
@Test
public void testGetProjectManager() {
// In order to give Jira time to initialize everything before we start
// handling things...There was an error saying that the
// ComponentAccessor was not initialised
navigation.gotoPage("/secure/project/ViewProjects.jspa");
ProjectManager pm= ComponentAccessor.getProjectManager();
}
As the code shows, I even included a previous step to navigate to a page, thinking that would make everything initialised in jira, without success.
Thanks in advance!
Community moderators have prevented the ability to post new answers.
When running unit tests, you need to mock API calls. The FuncTestCase stuff is for mocking user actions via UI and asserting the result from the UI, it won't help you with server side integration tests. see related question how-to-do-integration-testing-of-one-class-inside-a-running-instance-of-jira.
Hi Jose,
Are you still awaiting a response for this? Could you please include the section of your code which would indicate how you are using the ComponentAccessor class object and what methods you are calling on it? (If you dont declare the ComponentAccessor, you may be using the ComponentManager)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Luke,
I would be very interested in getting a response to this question.
The section of code that causes the error is this:
ProjectManager pm= ComponentAccessor.getProjectManager();
This is executing inside a test method of a class that extends com.atlassian.jira.functest.framework.FuncTestCase;
Thanks for your interest in this question.
José Marañón
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jose,
As Andy answered below, the best way is to Mock these objects, however I too am unsure as to how you would go about doing this for integration tests. Although if you are extending the com.atlassian.jira.functest.framework.FuncTestCase it would suggest that you are writing unit tests?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Uh no, FuncTestCases are integration test cases, the problem is they from 'out here' to 'in there' using http requests between. To run a test 'in there' is the trick. To reiterate 'out here' you have no running environment. You can use atlas-run yes, but that just spins up a local copy of 'in there', your test cases remain 'out here', Im pretty sure you will not get useful success trying to access ComponentAccessor like that, it only works 'in there' ?!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Petter,
No, I do not have a solution to this problem yet.
I guess that the cause is that the Atlassian SDK starts the container, Jira and the plugin in a JVM independent of the one that actually runs the tests. That would be the reason the tests do not "see" an active Jira instance.
My need is to test how some classes interact with the underlying Jira instance, without running a full functional test of the plugin.
Any idea will be welcome!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi José, did you get anywhere with this? I'm facing a similar problem with JqlQueryBuilder...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.