Mice, Will try to get back to you in depth on this email this weekend. Can you provide more detail about why ResourceManagerTest failed?
As for Mockito, I'm the one who suggested to remove it for the 4.0 release because no one was using it. It's MIT licensed. Maybe others can comment on whether that's compatible with apache license. If it is, I don't see any reason why not to bring it back. If we decide to bring it back or use some other mock library, I would say we should place them in a separate directory. Deps should be for code that gets deployed. That way people won't get confused about what CloudStack really depends on in deployment. For example, I often get questions why selenium, which is used in qa testing only, is in deps. --Alex > -----Original Message----- > From: Mice Xia [mailto:[email protected]] > Sent: Friday, August 10, 2012 2:25 AM > To: [email protected] > Subject: [Discuss] Unit test style > > Hi, Folks > > I'm about to write some unit tests for what I have committed. However it > seems a little bit heavy weight if I follow the guide > http://wiki.cloudstack.org/display/COMM/Unit+Testing+101 > > 1) About IoC, I had to inject all dependent DAOs/Managers for the class > under test, even if I want to test one method which needs only one or two > DAOs. Sure I can get it around by writing Mocks by implementing interfaces > but that results in a class with a lot of empty TODO methods. I wonder if it > fit > the convention to bypass the IoC and directly create dependency I needed, > suppose I don’t need it get configured or started automatically. > 2) About mocks/stubs, I know Mockito is removed from tree, but without a > mock utility, it is lengthy to create stub method(same reason as above). Any > chance that we can bring it back or find a replacement? > > ResourceManagerTest is an example of this, it injects almost everything for > one test method, and it still fails with red bar because of broken > dependencies. > > Following is a pseudo snip with Mockito mocks and without locator/injector, > it seems more neat and readable: > > [code] > StorageManager storageMgr = mock(StorageManager.class); > doReturn(true).when(storageMgr).storagePoolHasEnoughSpace(Arrays.asLi > st(volA), sp1); _firstFitPlanner._storageMgr = storageMgr; .... > ... > result =_firstFitPlanner.findPotentialDeploymentResources(....) > assertTrue(...) > [/code] > > Welcome any comments on this topic > > Regards > Mice
