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

This widget could not be displayed.

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());
      }

This widget could not be displayed.

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

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted yesterday in Canada

AUG Lunch Roundtable - August 13 - Highlights

Thanks to everyone who came out today for the lunch AUG - we had some great food and discussion (and ice cream sandwiches to fend off the heat!) The welcome and fun fact was great as well, what an aw...

28 views 1 3
View post

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