Unit Testing Jelly

19 views
Skip to first unread message

AndyB

unread,
Nov 25, 2014, 5:09:56 AM11/25/14
to jenkin...@googlegroups.com
Hi,

I have a question about unit testing. 

I have some tests that do a 'roundTrip' as described here: https://wiki.jenkins-ci.org/display/JENKINS/Unit+Test#UnitTest-Configurationroundtriptesting - that works nicely. It checks that the config page is populated correctly and the values make it back to a new object on a submit/save.  I want to extend the tests so that I modify some of the fields before submitting the form (so they go through form validation etc.). I've looked for some examples of this but haven't found any - could anyone point me to some code that does this? I've looked at the HtmlForm for the config but it's quite hard to figure out how that relates to the very simple Jelly textboxes I have. I basically just need to be able to set values in a number of text fields and then submit.  This should be easy shouldn't it? Any pointers appreciated.

Thanks
Andy

Jesse Glick

unread,
Nov 25, 2014, 10:49:40 AM11/25/14
to Jenkins Dev
On Tue, Nov 25, 2014 at 5:09 AM, AndyB <andy....@gmail.com> wrote:
> This should be easy shouldn't it?

Well, not exactly easy, but not that hard. Poke around in
jenkinsci/jenkins/test/src/test/java/ and you will find some tests
doing this kind of thing.

BTW if you mainly want to test form validation, it is easier to just
call the doCheck* methods directly. Testing them from the context of a
live form is going to be messier. For one thing, even errors will not
block the form from being submitted, so you would have to
screen-scrape the page before submitting. And beware that the checks
are done asynchronously, so you would need to use some HtmlUnit
utility method to wait for the results to come back.

AndyB

unread,
Nov 25, 2014, 11:52:45 AM11/25/14
to jenkin...@googlegroups.com

Hi Jesse,

Thanks for the pointers, I'll dig in and take a look - I'll be happy if I can just poke some text boxes to get started. I hadn't considered the async nature of validation checks, so thanks for that tip!   think it makes sense to check that the validation is being called as well as checking the correctness of the validation so I think there is some sense to testing that via the config page iteself.

Ta,
Andy
Reply all
Reply to author
Forward
0 new messages