-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Feedback: Need to consider how JSR303 will be Testable
PostPosted: Tue Apr 01, 2008 9:10 pm 
Newbie

Joined: Wed Nov 22, 2006 2:39 am
Posts: 2
The JSR303 draft specification does not discuss or even hint at how the proposed validation rules, expressed as annotations, might be unit tested.

In organizations that routinely use automated unit testing (I work in one), the cost of developing tests for application code often significantly exceeds the cost of writing it.

Therefore, it is insufficient to have a validation mechanism that is itself consise and flexible; one needs to be able to easily write unit tests that verify the applied validations are in fact operating.

In my organization (IBS in Melbourne, Australia) validation business logic is typically a major component of the work we do.

We encountered a similar problem with the JSR181 Web Service metadata annotations. Although its easy to add eg @WebService to a Service-Layer method, its harder to write a unit-integration test that verifies the method is now exposed as a web service endpoint within the web container.

In our case, the main obstacle was that we didn't typically want to test the body of the web service, its business logic, in the same test as verified it was web-exposed. Whether its WS-exposed should be orthogonal to testing what it actually does.

How does this apply to JSR303? Well, for starters, the ability to unit test a particular field validation rule in isolation, without (a) needing eg an app server running, and (b) firing all other validation rules, would be desirable.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 02, 2008 11:50 pm 
Newbie

Joined: Mon Mar 31, 2008 12:05 pm
Posts: 11
Quote:
The JSR303 draft specification does not discuss or even hint at how the proposed validation rules, expressed as annotations, might be unit tested.


The JSR 303 doesn't need to tell you how to write test cases. The purpose of the JSR is to outline the specification so the standard is fully expressed for various vendors to implement. Since most of the classes in the API are interfaces, you're free to create stubs or mock up your own implementations.

Quote:
In organizations that routinely use automated unit testing (I work in one), the cost of developing tests for application code often significantly exceeds the cost of writing it.


I don't mean to start argument here, but you don't understand the purpose of unit testing. Maybe you should grab a book on TDD and do some research on the subject.

Quote:
Therefore, it is insufficient to have a validation mechanism that is itself consise and flexible; one needs to be able to easily write unit tests that verify the applied validations are in fact operating.


You're totally missing the purpose of this JSR. It has *nothing* to do with unit testing. I can't see how its not testable since it doesn't require a container. You're Validators are just Java objects that are passed information that you can mock up.

Quote:
How does this apply to JSR303? Well, for starters, the ability to unit test a particular field validation rule in isolation, without (a) needing eg an app server running, and (b) firing all other validation rules, would be desirable.


Try reading the specification. In particular the review of the Validator<T> API.

I'm trying to be helpful, but please read the specification and try to contribute to the growth of the JSR and help flesh out any short comings to the API itself.

Best Regards,
Richard L. Burton III


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 03, 2008 2:19 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Here is how I unit test my validations.
If I want to unit test the actual validation implementation, I just instantiate the class and pass various values to it.
If I want to test my domain model validation. I instanciate a validator, I populate one of my domain model class with various wrong values, I check that the validator.validate() return the expect invalid constraints

The JSR runs on plain Java 5. There is no need for an app server.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.