Unit testing gadget

Hi All,

If you could see my list of questions asked so far, you can easily find that i am in the learning process of developing a jira gadget.

Well. Now here goes the question

I have a simple gadget with dropdown showing the list of projects available in the jira created by the users.

I have fetched the list of projects using JIRA API.

Now i would like to write a unit test for this gadget which i have developed.

I am sure that I have to use mock objects instead of JIRA api classes. But which "mock objects" framework suits well. Or is there a straightforward method to write the unit test cases?

As some may guess, my next question would be related to the integrated testing in case if i fail to come up with a good integration testing.

Thanks in advace.


2 answers

I get the following error

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 1.672 sec <<< FAILURE! testMyName(ut.test.project.info.gadget.MyComponentUnitTest) Time elapsed: 1.562 sec <<< ERROR! java.lang.IllegalStateException: ComponentAccessor has not been initialised. at com.atlassian.jira.component.ComponentAccessor.getWorker(ComponentAccessor.java:848) at com.atlassian.jira.component.ComponentAccessor.getComponentOfType(ComponentAccessor.java:124) at ut.test.project.info.gadget.MyComponentUnitTest.initialize(MyComponentUnitTest.java:40)

for the java junit code below

public class MyComponentUnitTest   {
      private ProjectInfoDetailsInterface component;
      private Logger logger ;
      private SearchService searchService;
      private JiraAuthenticationContext jiraAuthenticationContext ;
      private PermissionManager permissionManager ;
      private CustomFieldManager customFieldManager ;
      private ChangeHistoryManager changeHistoryManager ;
      private ComponentAccessor componentAccessor;
      public void initialize(){
            logger = Mockito.mock(Logger.class);
            searchService = Mockito.mock(SearchService.class);
            jiraAuthenticationContext = Mockito.mock(JiraAuthenticationContext.class);
            permissionManager = Mockito.mock(PermissionManager.class);
            customFieldManager = Mockito.mock(CustomFieldManager.class);
            changeHistoryManager = Mockito.mock(ChangeHistoryManager.class);
            componentAccessor =  Mockito.mock(ComponentAccessor.class);
      public void testMyName() {
            component = new ProjectInfoGetDetails(logger,searchService,jiraAuthenticationContext,permissionManager,customFieldManager,changeHistoryManager);

using Mockito i was able to Mock the classes in jira api

Suggest an answer

Log in or Join to answer
Community showcase
Alexey Matveev
Published Saturday in Jira

How to run Jira in a docker container

Everything below is tested on Ubuntu 17.10. I prefer to use Jira in a docker container because: 1. I can install Jira with a couple of commands. 2. I can start and stop Jira just by starting and s...

153 views 3 7
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot