incubator-cloudstack-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mice Xia" <mice_...@tcloudcomputing.com>
Subject [Discuss] Unit test style
Date Fri, 10 Aug 2012 09:24:31 GMT
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.asList(volA),
sp1);
_firstFitPlanner._storageMgr = storageMgr; ....
...
result =_firstFitPlanner.findPotentialDeploymentResources(....)
assertTrue(...)
[/code]

Welcome any comments on this topic

Regards
Mice
Mime
View raw message