On Wed, Nov 28, 2012 at 06:58:14AM +0530, David Nalley wrote: > On Tue, Nov 27, 2012 at 6:09 PM, Min Chen <min.c...@citrix.com> wrote: > > Hi there, > > > > In working with API refactoring work, I cannot help wondering how we > > should write Junit test cases for our APIs. Recently I saw that Chip has > > merged some of his API unit test cases into master branch, and his api > > unit test cases are written using Mockito, so no DB and real MS are needed > > in running these Junit test cases. Here I want to raise this topic again > > to get some clarifications on api unit test guidelines: > > 1. Should we require API unit test cases to be able to run without > > DB > > existing or MS running? > > 2. If answer is yes, then I guess that we just need to use Mockito > > to > > write our api unit test cases. > > 3. If answer is no, there are several follow-up questions to be > > clarified: > > 1) Does test case itself need to handle starting MS and stopping > > MS? > > 2) How should we set up a test DB? This may be needed for those > > list > > APIs. > > 3) Testcases need to handle tear down test data afterwards. > > > > Thanks > > -min > > > > So unit tests (IMO) should not need external resources to run, should > be very fast, etc as Sudha has indicated. > > If you need DB access, that sounds much more like a > functional/integration test to my ears. >
IMO if any layer should be unittest-able it should be the API. But if that's not possible if we stray away from the purist view of a unittest ie w.o the DB then we could run the tests against a database populated by the simulator. For the 300 or so APIs to be backed with unittests the simulator can easily produce various configurations of cloudstack with different zone models. The functional/integration suite does *NOT* test the API the way I would imagine we should test the API. For the API tests to be tested functionally over the course of this refactor we will need to ensure all request/response arguments and params remain undisturbed. And this is not something the integration suite does today. But it certainly can. -- Prasanna.,