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
Community showcase
Posted Friday in Europe

Venue Needed! 23rd October

Hey Everyone! Unfortunately, the venue that was hosting us on the 23rd has pulled out so we're looking for a new venue.    If anyone would have a room free that we could use on the ev...

39 views 1 0
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