Re: Unit testing logic / EOF
Re: Unit testing logic / EOF
- Subject: Re: Unit testing logic / EOF
- From: Chuck Hill <email@hidden>
- Date: Thu, 22 Nov 2007 18:45:24 -0800
Hi Jean-François,
On Nov 22, 2007, at 1:12 PM, Jean-François Veillette wrote:
I'm relatively new to unit testing, junit, selenium and all that
stuff.
I'd suggest going straight to TestNG rather than using JUnit. I have
found TestNG to be easier to control and configure than JUnit.
I've built simple test so far for logic that didn't involve
database operation and didn't invole much of eof in fact.
I have to modify an existing project and would like to start
building test cases for it, slowly but surely building a test library.
That is a good plan.
Trying to build test for logic related to registration and
membership management.
For example, when I do invoke registerNewUser("New User Name"), I
would like to make sure that an invoice object is created, with the
correct type and amount in it, depending on the current cost grid,
which will depend on the current date (system pref).
I have looked at wounittest and the mockeditingcontext. it is
interesting ... but since I'm so new to all of this, I'm not even
sure I really understand how it can really be useful for me. At
least I can't get to write a test that doesn't just look like «
assertEqual(2, 2) » and really test the logic, verifying new
objects and relationships.
When I'm thinking about the fact that I'm going to test the
membership movements (across many groups), I think in term of a
graph of sequential operations, where each node is a new state with
check points, and each childs are optional operations that can be
done from that point.
How do you handle such situation ?
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 also use Design by Contract with greatly reduces the need to write
unit tests as much of the code tests itself. I try to keep in mind
"only test what can break" as "only test what you might have possibly
written incorrectly" and don't write tests for very simple methods.
Test what is useful to test, don't test things just because you can.
If each node become a test (@Test), then just having the objects
context ready will be quite challenging. How do you build a test
from the result state of a previous test ?
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.
The second though is that tests should clean up behind themselves.
Tests should restore data that they modify. The only exceptions to
this is data that is (a) loaded/replaced by DBUnit when the tests
start and (b) needed in its modified state by a later test.
Again, TestNG helps here. It is very easy to define dependancies
between tests (either across test classes or even within methods in a
test class) so that Test B always runs after Test A
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.
How many of you are using junit ? wounittest ? testng ?
Selenium and TestNG.
In this first step, I'm not yet interested in component testing
(ERSelenium), we have enough logic code to test before the user
interface layer come to play.
And you will constantly face the most important question: "How much
testing is enough?"
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