Unit testing gadget

Kannan S November 18, 2013

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

0 votes
Kannan S December 16, 2013

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

0 votes
Kannan S November 18, 2013

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events