Return-Path: X-Original-To: apmail-incubator-cloudstack-dev-archive@minotaur.apache.org Delivered-To: apmail-incubator-cloudstack-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 49941EE3F for ; Tue, 12 Feb 2013 01:36:39 +0000 (UTC) Received: (qmail 74905 invoked by uid 500); 12 Feb 2013 01:36:38 -0000 Delivered-To: apmail-incubator-cloudstack-dev-archive@incubator.apache.org Received: (qmail 74875 invoked by uid 500); 12 Feb 2013 01:36:38 -0000 Mailing-List: contact cloudstack-dev-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list cloudstack-dev@incubator.apache.org Received: (qmail 74861 invoked by uid 99); 12 Feb 2013 01:36:38 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Feb 2013 01:36:38 +0000 X-ASF-Spam-Status: No, hits=-5.0 required=5.0 tests=RCVD_IN_DNSWL_HI,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of Alex.Huang@citrix.com designates 66.165.176.89 as permitted sender) Received: from [66.165.176.89] (HELO SMTP.CITRIX.COM) (66.165.176.89) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 12 Feb 2013 01:36:32 +0000 X-IronPort-AV: E=Sophos;i="4.84,646,1355097600"; d="scan'208";a="7105137" Received: from sjcpmailmx02.citrite.net ([10.216.14.75]) by FTLPIPO01.CITRIX.COM with ESMTP/TLS/RC4-MD5; 12 Feb 2013 01:36:10 +0000 Received: from SJCPMAILBOX01.citrite.net ([10.216.4.73]) by SJCPMAILMX02.citrite.net ([10.216.14.75]) with mapi; Mon, 11 Feb 2013 17:36:10 -0800 From: Alex Huang To: Alex Huang , Anthony Xu , "cloudstack-dev@incubator.apache.org" Date: Mon, 11 Feb 2013 17:36:16 -0800 Subject: RE: how to write Unit test which requires DB setup Thread-Topic: how to write Unit test which requires DB setup Thread-Index: Ac4IpuozWGmS0t6yQ/65ypIhM9PtQQAD+zkQAAJyvFA= Message-ID: References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Virus-Checked: Checked by ClamAV on apache.org SecurityGroupManagerImpl2Test.java for how to inject mocked daos, managers,= and adapters. =20 To return actual values to test out your business logic, you have can do lo= ok 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 >=20 > Mock your db access. Basically mock up the Dao objects to return the res= ults > you expect. >=20 > --Alex >=20 > > -----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 s= etup > is > > needed and some pre-test DB initial entries are also needed. Is there a= ny > > 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 acces= s? > > > > Your comment is highly appreciated! > > > > Anthony