New Posts New Posts RSS Feed: Unit testing Entities
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Unit testing Entities

 Post Reply Post Reply
Author
Dominique View Drop Down
Groupie
Groupie
Avatar

Joined: 28-Jun-2007
Location: Norway
Posts: 44
Post Options Post Options   Quote Dominique Quote  Post ReplyReply Direct Link To This Post Topic: Unit testing Entities
    Posted: 07-Dec-2007 at 1:24pm
Hi David,

Thanks for your answer.

Originally posted by davidklitzke

Why do you want to avoid "hitting the database"? 

Going to the db will take some times and require to manage a test set in the database. In many case I just want to make a small unit test.

Originally posted by davidklitzke

You should start your most of your unit tests by creating a new instance of a PersistenceManager, in which case there will be nothing in the cache.   

I was afraid that it would grow to a point where my test take for long time. I have a so low test coverage (:oops:) that it is actually not a problem right now but I am up to almost 10s for the part the unit test (not file, db test). I hope that it won't grow linear.

Originally posted by davidklitzke

In any case, you shouldn't have any dependencies going from one test to another. 

I totally agree with that, wich means that many test will need to do som setup/teardown to the base also when testing "pure logic".

I'll follow your advice of using a new PersistManager and see how it goes. If it make testing easier and doesn't consume too much time, that will be good enough for me.


Edited by Dominique - 07-Dec-2007 at 1:24pm
Dominique
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 07-Dec-2007 at 8:52am
Why do you want to avoid "hitting the database"?  Almost all of our unit tests use a "test" database.  If you don't need to use a database to get your data, that's fine too, but I wouldn't go out of my way if using a database is easier.
 
You should start your most of your unit tests by creating a new instance of a PersistenceManager, in which case there will be nothing in the cache.  In any case, you shouldn't have any dependencies going from one test to another.
Back to Top
Dominique View Drop Down
Groupie
Groupie
Avatar

Joined: 28-Jun-2007
Location: Norway
Posts: 44
Post Options Post Options   Quote Dominique Quote  Post ReplyReply Direct Link To This Post Posted: 06-Dec-2007 at 11:40pm
Hi,

I can't find a good solution for writing unit tests without hitting the database. Do you have any tips on how I could do that?
My first problem is the management of the enum classes, it looks like you need to go to the db to initialize them. An other point is the management of the cache between test, how can I clean the cache of entities created in the test without reaping off initial values like enum classes?

Thanks for any advice :)
Dominique
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down