Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Best way to unit test a simple jira plugin

Joseph Kelroy July 16, 2018

I am new to jira plugin development and am creating my first plugin but I am having trouble unit testing. My main question is what is the best way to unit test a function that uses ComponentManager. Should I try to mock everything, do I have to use dependencies to test, or should I just save something like this for an integration test? All questions I have read using ComponentAccessor in unit testing do not work.

Trying to mock(ComponentAccessor.class) does not work because it is still null and when I try to use a 

when(ComponentAccessor.getIssueLinkManager().getOutwardLinks(epic.getId())).thenReturn(Collection<IssueLink. links);

It still says componentAccessor has not been initialized.

I have tried using mocks and adding jira-tests as a dependency to be able to use MockComponentWorker and MockitoMocksInContainer but the classes seem to not know anything about these and their imports. To me it seems like I have to write everything from scratch but I have seen people use an import like this

import com.atlassian.jira.junit.rules.MockComponentContainer;

But no dependency I use seems to know about anything like this.

Below describes my set up more:

I have a simple plugin that uses the tutorial https://developer.atlassian.com/server/jira/platform/adding-content-to-the-jira-view-issue-page/ to roll up all issue times into an epic, instead of what the tutorial java class does. So it uses the same .java class in src/main/java/com that extends AbstractJiraContextPorvider.  Inside here I have a method that uses the line 

final Collection<IssueLink> links = ComponentAccessor.getIssueLinkManager().getOutwardLinks(epic.getId());

 

When I try to test it I am getting the error ComponentAccessor not initialized. Along with  

"Developers that encounter this message within a unit test
should use n MockitoMocksInContainer rule to initialize mockito and ComponentAccessor.
For more detailed explanation read the documentation
for MockComponentWorker in the jira-tests artifact for more information
about what causes this error and how to address it."

 

Any suggestions/comments on any type of testing I would appreciate! Thanks

 

1 answer

0 votes
Al Johnson March 5, 2020

Why isn't there an answer from Atlassian yet?

Suggest an answer

Log in or Sign up to answer