Re: Unit testing logic / EOF
Re: Unit testing logic / EOF
- Subject: Re: Unit testing logic / EOF
- From: Chuck Hill <email@hidden>
- Date: Tue, 27 Nov 2007 14:46:12 -0800
On Nov 27, 2007, at 1:59 PM, Jean-François Veillette wrote:
Warning: I may have a somewhat heretical approach to testing. But
it works well for me.
I don't use WOUnitTest nor MockEditingContext. I use a real
EOEditingContext and often fetch from and save to the database.
This makes the test run more slowly than "traditional" unit
tests. However, I think the advantages of really getting EOF
involved (and finding bugs early) outweigh the slowness.
Also, with TestNG it is easy to have multiple groups of tests.
You can run the fast group often and the EOF group before you commit.
I started using JUnit 4.x, not going with TestNG for now. I first
want to « make it work », later on it will be « make it right ».
As a newcommer, I wanted to minimize the unknown (not to mention
that the documentation and tutorial for TestNG is either short or
inexistant), so I stayed with junit on short term. But it look
like an easy and obvious migration step from junit. So I thought,
I will get the concept, get it to do what I want, then the
migration to TestNG should be easy.
Makes sense. And yes, migrating from JUnit to TestNG is not hard,
just typing.
I'm using a real database for my test (not the MockEditingContext),
for many reason, but want to minimize the modifications needed just
to add automated test.
In my test method, every time I create an objet, I also put it in
the release-pool (an nsmutablearray). In @After, I delete from
every eo-objects in the release-pool. That keep my db clean after
every run of the test.
My thinking is that on long term it will be easier to reuse the
database setup test objects than to constantly rewrite mock objects
depending on the current test.
That sounds similar to what I am doing.
For now, I have a DA that trigger the test run. This way I'm sure
that EOF initialisations are all done. It will be ok on short
term, but I'll soon need to find an elegant way to run the test
without having the test code inside the deployed app.
It is fairly easy to do from within Eclipse, but that can wait.
I have two thoughts on that. One is that I use DBUnit (http://
www.dbunit.org/) to set up a known set of data before running my
unit tests. That gives me a known starting point.
I looked at dbunit, it will be a nice addition latter on, again, I
have enough new stuff to deal with for now.
I agree. I just wanted you to be aware of it.
If you have sample code showing more than the basic test (even if
I can't compile, at least if I can understand), that would be
great !
I don't think I have anything that would mean much without the
context of the model and EO classes. If you want to show some
code and ask, "How do I test X" I would be happy to share my
thoughts.
I would still be interested to see a real test class written by
experienced and talented people,
I am pretty sure I don't have any of those. :-)
just to see how much code It's needed, what are the best-practices
used, etc.
I will see what I can find. I have two problems. One is that I use
DBC and that greatly affects (reduces) the number of tests that I
write. My examples might not show what you need to do very well.
The second problem is that most of the tests are in code that is
under NDA. The code for GVC.SiteMaker is mostly test free (long
story, bad decision, my fault). The tests in our frameworks are
probably not very close to what I would put in an app (different
goals). I will see what I can find.
Chuck
--
Practical WebObjects - for developers who want to increase their
overall knowledge of WebObjects or who are trying to solve specific
problems.
http://www.global-village.net/products/practical_webobjects
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden