You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cloudstack.apache.org by Anthony Xu <Xu...@citrix.com> on 2013/02/11 23:27:00 UTC

how to write Unit test which requires DB setup

Hi all,

I'm trying to write some unit tests for network manager, I believe DB setup is needed and some pre-test DB initial entries are also needed. Is there any unit test frame work to setup DB and populate some initial data into DB before launching the unit test?  Or is there other way to mock DB access?

Your comment is highly appreciated!

Anthony


Re: how to write Unit test which requires DB setup

Posted by Min Chen <mi...@citrix.com>.
You can also look at ApiRateLimitTest, where I have mocked
ConfigurationDao.

Thanks
-min

On 2/11/13 5:47 PM, "Anthony Xu" <Xu...@citrix.com> wrote:

>Strange , I didn't see any mock in SecurityGroupManagerImpl2Test.java, in
>SecurityGroupManagerTestContext.xml?
>
>
>Anthony
>
>> -----Original Message-----
>> From: Alex Huang
>> Sent: Monday, February 11, 2013 5:36 PM
>> To: Alex Huang; Anthony Xu; cloudstack-dev@incubator.apache.org
>> Subject: RE: how to write Unit test which requires DB setup
>> 
>> SecurityGroupManagerImpl2Test.java for how to inject mocked daos,
>> managers, and adapters.
>> 
>> To return actual values to test out your business logic, you have can
>> do look at the mockito website on how to mock methods to return values.
>> 
>> http://code.google.com/p/mockito/
>> 
>> --Alex
>> 
>> > -----Original Message-----
>> > From: Alex Huang [mailto:Alex.Huang@citrix.com]
>> > Sent: Monday, February 11, 2013 4:22 PM
>> > To: Anthony Xu; cloudstack-dev@incubator.apache.org
>> > Subject: RE: how to write Unit test which requires DB setup
>> >
>> > Mock your db access.  Basically mock up the Dao objects to return the
>> results
>> > you expect.
>> >
>> > --Alex
>> >
>> > > -----Original Message-----
>> > > From: Anthony Xu [mailto:Xuefei.Xu@citrix.com]
>> > > Sent: Monday, February 11, 2013 2:27 PM
>> > > To: cloudstack-dev@incubator.apache.org
>> > > Subject: how to write Unit test which requires DB setup
>> > >
>> > > Hi all,
>> > >
>> > > I'm trying to write some unit tests for network manager, I believe
>> DB setup
>> > is
>> > > needed and some pre-test DB initial entries are also needed. Is
>> there any
>> > > unit test frame work to setup DB and populate some initial data
>> into DB
>> > > before launching the unit test?  Or is there other way to mock DB
>> access?
>> > >
>> > > Your comment is highly appreciated!
>> > >
>> > > Anthony
>


RE: how to write Unit test which requires DB setup

Posted by Anthony Xu <Xu...@citrix.com>.
Strange , I didn't see any mock in SecurityGroupManagerImpl2Test.java, in SecurityGroupManagerTestContext.xml?


Anthony

> -----Original Message-----
> From: Alex Huang
> Sent: Monday, February 11, 2013 5:36 PM
> To: Alex Huang; Anthony Xu; cloudstack-dev@incubator.apache.org
> Subject: RE: how to write Unit test which requires DB setup
> 
> SecurityGroupManagerImpl2Test.java for how to inject mocked daos,
> managers, and adapters.
> 
> To return actual values to test out your business logic, you have can
> do look at the mockito website on how to mock methods to return values.
> 
> http://code.google.com/p/mockito/
> 
> --Alex
> 
> > -----Original Message-----
> > From: Alex Huang [mailto:Alex.Huang@citrix.com]
> > Sent: Monday, February 11, 2013 4:22 PM
> > To: Anthony Xu; cloudstack-dev@incubator.apache.org
> > Subject: RE: how to write Unit test which requires DB setup
> >
> > Mock your db access.  Basically mock up the Dao objects to return the
> results
> > you expect.
> >
> > --Alex
> >
> > > -----Original Message-----
> > > From: Anthony Xu [mailto:Xuefei.Xu@citrix.com]
> > > Sent: Monday, February 11, 2013 2:27 PM
> > > To: cloudstack-dev@incubator.apache.org
> > > Subject: how to write Unit test which requires DB setup
> > >
> > > Hi all,
> > >
> > > I'm trying to write some unit tests for network manager, I believe
> DB setup
> > is
> > > needed and some pre-test DB initial entries are also needed. Is
> there any
> > > unit test frame work to setup DB and populate some initial data
> into DB
> > > before launching the unit test?  Or is there other way to mock DB
> access?
> > >
> > > Your comment is highly appreciated!
> > >
> > > Anthony


RE: how to write Unit test which requires DB setup

Posted by Alex Huang <Al...@citrix.com>.
SecurityGroupManagerImpl2Test.java for how to inject mocked daos, managers, and adapters.  

To return actual values to test out your business logic, you have can do look at the mockito website on how to mock methods to return values.

http://code.google.com/p/mockito/

--Alex

> -----Original Message-----
> From: Alex Huang [mailto:Alex.Huang@citrix.com]
> Sent: Monday, February 11, 2013 4:22 PM
> To: Anthony Xu; cloudstack-dev@incubator.apache.org
> Subject: RE: how to write Unit test which requires DB setup
> 
> Mock your db access.  Basically mock up the Dao objects to return the results
> you expect.
> 
> --Alex
> 
> > -----Original Message-----
> > From: Anthony Xu [mailto:Xuefei.Xu@citrix.com]
> > Sent: Monday, February 11, 2013 2:27 PM
> > To: cloudstack-dev@incubator.apache.org
> > Subject: how to write Unit test which requires DB setup
> >
> > Hi all,
> >
> > I'm trying to write some unit tests for network manager, I believe DB setup
> is
> > needed and some pre-test DB initial entries are also needed. Is there any
> > unit test frame work to setup DB and populate some initial data into DB
> > before launching the unit test?  Or is there other way to mock DB access?
> >
> > Your comment is highly appreciated!
> >
> > Anthony


RE: how to write Unit test which requires DB setup

Posted by Anthony Xu <Xu...@citrix.com>.
Is there any example in Cloudstack?

Anthony

> -----Original Message-----
> From: Alex Huang
> Sent: Monday, February 11, 2013 4:22 PM
> To: Anthony Xu; cloudstack-dev@incubator.apache.org
> Subject: RE: how to write Unit test which requires DB setup
> 
> Mock your db access.  Basically mock up the Dao objects to return the
> results you expect.
> 
> --Alex
> 
> > -----Original Message-----
> > From: Anthony Xu [mailto:Xuefei.Xu@citrix.com]
> > Sent: Monday, February 11, 2013 2:27 PM
> > To: cloudstack-dev@incubator.apache.org
> > Subject: how to write Unit test which requires DB setup
> >
> > Hi all,
> >
> > I'm trying to write some unit tests for network manager, I believe DB
> setup is
> > needed and some pre-test DB initial entries are also needed. Is there
> any
> > unit test frame work to setup DB and populate some initial data into
> DB
> > before launching the unit test?  Or is there other way to mock DB
> access?
> >
> > Your comment is highly appreciated!
> >
> > Anthony


RE: how to write Unit test which requires DB setup

Posted by Alex Huang <Al...@citrix.com>.
Mock your db access.  Basically mock up the Dao objects to return the results you expect.

--Alex

> -----Original Message-----
> From: Anthony Xu [mailto:Xuefei.Xu@citrix.com]
> Sent: Monday, February 11, 2013 2:27 PM
> To: cloudstack-dev@incubator.apache.org
> Subject: how to write Unit test which requires DB setup
> 
> Hi all,
> 
> I'm trying to write some unit tests for network manager, I believe DB setup is
> needed and some pre-test DB initial entries are also needed. Is there any
> unit test frame work to setup DB and populate some initial data into DB
> before launching the unit test?  Or is there other way to mock DB access?
> 
> Your comment is highly appreciated!
> 
> Anthony