It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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.

Kannan.S

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;
      
      @Before
      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);
            when(componentAccessor.getComponentOfType(SearchService.class)).thenReturn(searchService);
      }
 
      @Test
      public void testMyName() {
            component = new ProjectInfoGetDetails(logger,searchService,jiraAuthenticationContext,permissionManager,customFieldManager,changeHistoryManager);
            System.out.println(component.getProjects());
      }

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Expose your beautifully crafted Dashboard through the Jira Service Desk Customer Portal

  A picture is worth a thousand words, especially when you're trying to find relationships and understand your data. Here, Dashboards play a vital role in gaining insights from a variety of dat...

272 views 5 4
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you