• Home
  • RSS Feed
  • Log in

Testing Wicket with Fitnesse
Posted by Mischa Dasberg at around evening time: July 6th, 2008

On our latest project, My colleague Tjeerd Kaastra and I, have been using Wicket.
Since our GUI was so complex, and we had to write 100s of unit tests (a lot of corner cases), we sat down with our testers to find out how we should approach this. Because Our testers use Fitnesse to test both functional acceptance as well as regression tests, they test a lot of the code as well. So we thought, why not integrate the two and that is what we did.

This blog describes how to test Wicket applications using Fitnesse. It is about stretching the limits of the Wicket test components to do so. We will try to explain this by using a small example project we have created to illustrate things. This example project has been inspired on the new user wizard example by Eelco Hillenius. We adapted this example so that it uses Spring, because most apps use a backend system.


For those who don't know what Fitnesse is: FitNesse is a web server, a wiki, and a software testing tool. FitNesse allows users to enter specially formatted input (its format is accessible to non-programmers). This input is interpreted and tests are created automatically. So Fitnesse offers great options for automated testing beyond your unit tests. Wicket has got some utilities to unit test your application GUI outside a container. These components are org.apache.wicket.util.tester.WicketTester and specifically for Form components there is org.apache.wicket.util.tester.FormTester. Would it not be great if we could use these unit test components for functional testing in Fitnesse?

Forms can be tested using the FormTester. But unfortunately, the FormTester is meant to test one form and as usual in a unit test, you write a seperate testcase per scenario. From a functional point of view, you might want to test a form submit, then go back to the page, correct some validation issues and re-submit the form.
In real life, we used an abstract fixture class to provide all the generic methods and an extended fixture that gives us all the implementation details (like the correct application context, model class, start page, etc). The abstract fixture has for instance methods to check if components exist, set and select methods and lots more. See the example project.
Furthermore, throughout the code you will see several boolean return values that seem unused. This is a fitnesse best-practice. Whenever a boolean is returned, the Fitnesse test will color the result cell green or red so you can verify that the method was executed.

Testing the wizard
So for those who do not know the Wizard component, a wizard component is a dialog component that takes it's users through a number of predefined steps. It has common functionality like a next, previous, finish and cancel button, and it uses a transition rules to let clients navigate through it's steps.

Here's a typical fitnesse table that you might want to use to test your flow:

Look's easy enough, right? Well, there are quite some steps to take to achieve this easy testing scenario, and of course a couple of problems.

Problem 1: using field values instead of index numbers
Normally, using WicketTester you must define indexes for all fields that you want to test. When writing unit tests, this is not a problem but since we want to cater for functional testing, we will have to use reflection to achieve this.

We will not be going in to the ReflectionUtils, but the setFieldValueThroughSetMethod sets a value for a specific field through the corresponding Set method.
Since we tend to use ListView components for repeating form elements, we also added a special method to be able to add a value to a component at a certain position in the list that the ListView uses.

Problem 2: submitting multiple times and keeping you feedback
The actual submit has several problems to solve:
FormTester only allows one RequestCycle, meaning you can only submit a form once after which you must setup your testcase again. The formtester also does not update the model since it only tests one step.
Since the submit only tests the local step, we have to call .onSubmit() on the Next-button to proceed to the next step.
Feedback messages get lost if you submit a form using both FormTester and WicketTester. When you set a field value, store this value in a Map that will be used as a cache.

On submit, first retrieve the WebSession and remove all feedback messages.
Then set any field values that you have cached on the form again.
We then submit the FormTester to validate the form behavior and when all goes well (meaning there are no error messages caused by validating the form entries) we move to the next step.

Problem 3: ListViews do not get rendered automatically
Because you cannot update values on unrendered components, we will have to render our ListView components manually. Therefore, when moving to another step, we should render the components, see RenderComponents() in the Abstract Fixture.

Problem 4: Map values to Object attributes.
Because rendered values are Strings, for Example in our example application we have a User object which has a List of Role's, we only display the roleName of the Role object.
We need to be able to map an input string to an Object attribute.
So if in fitnesse we say

One of the nice things about a component-based framework is that your GUI components are backed by real Java objects. However, this makes it harder to test if a field is filled as expected. When setting up a fixture, we need to create a map of Object types and their corresponding GI fields.
Add this to your initialize method:
addTypeAndFieldName("Role", "roleName");
addCustomComponent("org.apache.wicket.markup.html.basic.Label");
addCustomComponent("org.apache.wicket.markup.html.list.ListView");

So lets illustrate a couple of tests.

Test 1:
- Check if the expected components exist on the NewUserWizardPage.

In your browser the page look like this:

The fitnesse test looks like this:

As you can see it is easy and readable. As you can see, our test is comform point 3. The testers do not need to fill in the Fully Qualified Name for RequiredTextField. To be able to do this, we keep an internal map of components fully qualified names. If you have Components that does not reside in the package org.apache.wicket.markup.html.form., you have to add them by adding a line like addCustomComponent("org.apache.wicket.markup.html.basic.Label"); to the initialize method in the fixture.)

Test 2:
- Press the "Next" button and check if there are any errors and if we are on the correct Step in the wizard.

In your browser the page look like this:

The fitnesse test looks like this:

Test 3:
- Fill in username and press the "Next" button and check if there are any errors and if we are on the correct Step in the wizard, then fill in email address and press the "Next" button and check if there are any errors and if we are on the correct Step in the wizard.

The fitnesse test looks like this:

These are just a few examples of how to test you wicket application using fitnesse.
As you can see, it make it very easy to test and it is readable!!

By combining the power of Fitnesse and Wicket , we are enabling non-techies to write automated tests. This way, your UI is tested completely in each iteration within a few hours, this gives us a major quality improvement and it really speeds up the testing (imagine how much time it would take to do a regression test by hand!). Our project proved the combination to be very valuable to both developers, testers and our customer.

The sources of the example project can be found here. Read the installation.txt file in the directory src/main/documents to get you started with the example app.

  • Share/Bookmark

Filed under Ajax, Java, Spring, Testing, Wicket | 7 Comments »



7 Responses to “Testing Wicket with Fitnesse”



    Eelco Hillenius Says:
    Posted at: July 6, 2008 at 10:39 pm

    Cool, thanks for writing up the article.

    One of the main focusses of Wicket 1.5 will be improved automatic testing. Your participation (in discussions, patches, etc) would be highly appreciated! :-)



    PY Says:
    Posted at: July 7, 2008 at 11:47 pm

    Great article.
    But it places the fitnesse test on a “StutsTestCase” like level.
    What about an integration Fitnesse+Selenium for a global regression + functional testing?
    Advantage would be to test javascript and end-user experience as well.



    Mischa Dasberg Says:
    Posted at: July 13, 2008 at 12:03 am

    @Eelco, that would be great!



    Timo Rantalaiho Says:
    Posted at: July 18, 2008 at 6:11 am

    Thanks for the effort and sharing it! This is indeed interesting, I’ll have a closer look on the WicketTester issues you mentioned, this already caught my attention:

    “Normally, using WicketTester you must define indexes for all fields that you want to test.”

    What do you mean exactly?

    Also, you might be interested in looking at jdave-wicket ( http://www.jdave.org/ ) if you’re interested in automatic Wicket testing. Some of the WicketTester issues that you mention also bite you there, but it makes it a bit easier to create descriptive tests (specs really) and offers some nice convenience utilities to use when testing Wicket.

    Cheers!



    Mischa Dasberg Says:
    Posted at: July 21, 2008 at 1:04 pm

    Normally you will do something like this:

    formTester.select(”markupId”, position);

    What we wanted is that a tester can say:

    | select | role | with value | admin |

    and we will find the position of the role with that value, so the tester will know for sure that he selected the correct value.



    Carl Says:
    Posted at: July 22, 2008 at 5:00 pm

    We’re been using Fitnesse and WicketTester for some time too.

    For the feed back we use getMessages on the BaseWicketTester rather than the FormTester.

    You just need to call Session.get().cleanupFeedbackMessages() after you have checked for the expected feedback.



    Mischa Dasberg Says:
    Posted at: July 23, 2008 at 11:14 am

    That’s what we did.

    Before we submit we remove the feedbackmessages by calling a method clearErrorMessages() which does exactly what you said. We remove the feedbackmessages each time we submit, because we can submit multiple times using our Fitnesse fixture.



Leave a Reply

Click here to cancel reply.

Deployment automation for Java application running on Websphere, WebLogic and JBoss

Archives

  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • August 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009

Xebia Sites

  • Xebia Corporate
  • Xebia France
  • Xebia India

Categories

  • Java (279)
  • Agile (109)
  • General (50)
  • Testing (42)
  • Performance (42)
  • Hibernate (36)
  • Scrum (33)
  • Podcast (31)
  • Architecture (31)
  • Spring (28)
  • SOA (24)
  • Maven (22)
  • Project Management (22)
  • Flex (17)
  • JPA (17)
    • JPA implementation patterns (13)
  • Eclipse (15)
  • Quality Assurance (14)
  • Middleware (19)
  • Frameworks (13)

Tag Cloud

    Seam XML esb Maven fitnesse Closures Xebia Hibernate Agile qcon Spring Functional Programming Architecture Grails Testing Poppendieck Scala Introduction to Agile Performance SOA Lean Groovy Agile Awareness Workshop JavaOne Semantic Web Ajax product owner IntelliJ Scrum Java
medicin depression buy phentermine without a perscription aricept generic hair loss help how do you prevent bone loss urinary tract infection symptoms viagra sex domination cialis viagra cures for throat infection buy sumycin acne care new medication for cancer treatment help for sleeping problems on-line pharmacies cure snoring medications to help clot blood what is aspirin buy zestoretic bronchitis vs pneumonia back pain muscle acne face medication muscle women pain behind knee fat blocker man health arthritis natural cure woman health women insomnia cheap phentermine online cats and irritable bowel syndrome buy cialis generic online nutritional diet for osteoporosis abnormal blood clots treatments for hair loss what is zyprexa dental whitening products impotence herbs drugs for diabetes allergy prevention buy canada levitra Mentax adhd in children hair loss in woman medicines for blood clot online imitrex viagra buy free dog products clindamycin drug how to stop hair loss chloramphenicol discount drug viagra what valium does permanent hair loss heart failure medicine avapro 150mg ordering viagra online food allergies order viagra online online viagra prescription carisoprodol mg improve your skin discount erectile dysfunction medication buy xanax online buy order viagra scabies teatments information allegra vitamine b1 diazepam breast cancer support free stop smoking cipro side effects ultram cheapest treatment attention deficit disorder discount vitamins supplements how to get viagra online synthroid buy cheapest cialis zyrtec online how to clear acne preventive osteoporosis immune stimulants what is hoodia On Line Viagra getting over the pain diflucan dosage health asthma online stores hair loss products blood clot drugs colon parasites hair loss products discount medicine pravastatin buy griseofulvin tablets order indomethacin dog health products how to take a beta-blocker diazapan is valium treating cold sores chronic pain drug what is osteoporosis stress drug tooth whitening lowering cholesterol naturally legality of buying cialis online order levitra treatment for insomnia cheapest cialis index depakote overdose alprazolam condom sales treatment of yeast infection xanax sales taking viagra after cialis how to control pain new birth control chest pain health prozac prescription blood clots viagra in mexico chlamydia pill cancer drugs cold flu drugs how do i order viagra online super viagra acyclovir medicine benadryl dosage erythromycin pregnancy buy contoured condom chronic muscle pain pet health dogs treatment attention deficit disorder dental teeth whitening asthma medicine free prescription drugs herpes drug diabetes treatment buy tooth whitening gel cheap fast valium generic levitra buy cheapest viagra online lopressor drug pharmacy drug prices ultram dosing treatments for bipolar disorder neurontin withdrawal parasite medication chlamydia tips for increasing breast size ways to enhance breast what is valium used for metformin tablet order birth control hair loss for men how does xanax work treatment hepatitis c rythmol cheap acai antioxidants nexium generic blood pressure pills levitra online no prescription Levitra Online medications on line motion sickness drugs bactrim online order roxithromycin nicotine where can i order viagra immune supplements buy erexin v bph prostate allopurinol xanax for depression drug new smoking stop cheap impotence drug generic cialis delivery new treatment for depression antibiotics for cat viagra china alternative medicine cholesterol viagra dose anxiety disorder treatment severe muscle pain treatment of cancer calcium carbonate penis enlargement without pill valium maximum dosage reasons for high blood pressure energy product breast enlargement info cheap effexor building your body wrinkle cream aricept dosage alpha blocker increasing female sex drive valium depression new pain meds no rx xanax drug trileptal mg imitrex avapro 150mg medicine drugs contraception female claritin pill medication for acne med orders buy viagra internet levitra effect treatment for blood clots order sominex buy creatine buy precose cheap viagra overnight lopressor drug body building info health drugs general health and medical what is diazepam eye infections in dogs online prescription pills diclofenac tablet new medication anxiety buy citalopram medication male enhancement enhancement fat blocker medicine for throat infection order cardizem about soma health remedies for dogs generic xanax cheap zyrtec for depression medicine viagra sex domination buy acne skin care product hypnosis help study cure vaginal yeast infection weight loss supplement program muscle pain in leg how to increase erection buy viagra what is cla augmentin doses gaining muscle mass health med online heart rate treatments lopressor drug dog ear canal phentermine without prescription viagra order online weight loss glipizide diabetes astelin generic fat blocker buy gel tooth whitening cheap wellbutrin online weight loss program buy antiox anti-biotics acne skin treatmen tramadole vpxl pill drugs affecting levitra immune system support augmentin hypothyroidism medication buy erexin v uy prescription medication without a prescription buy discount order osteo arthritis online buy pilocarpine cheapest place to buy phentermine parasite treatment impotence help body fat loss viagra herb alternative constipation supplements treatment dementia adhd and medications muscle spasm relief viagra online cheap relieve upper back pain stop hair loss discount viagra online menstrual cycle problems antifungal shampoo side effects ativan gabapentin medication where can i buy viagra diazepam buy soma online clonidine dosage viagra gel top hair loss fast antibiotics cure chlamydia skin fungal infections drug zofran give up smoking alternative medicine cholesterol sleeping help best online viagra scams prednisone 10mg viagra sex domination lotensin easy weight loss pain meds without prescription over the counter drugs new high blood pressure medic generic compazine cetirizine drug order phentermine best fat blockers woman enhancement supplement drug zofran buy precose new drug treatment for cancer how to increase fertility viagra in australia benadryl dosing buy alcoholism medications order l arginine buy diazepam generic for ativan ativan prescription drugs weight loss treatment for chest pain woman health where can i buy phentermine online skin fungal infection give up smoking viagra on line hoodia information how does osteoporosis occur buy viagra online buy alcoholism medications depakote overdose klonopin pill tetracycline capsules what is high blood pressure bladder control for dogs generic for lipitor glucophage online pharmacy gabapentin dosage treating yeast infections dog health info cymbalta anxiety cheap tramadol without prescription hydrea drugs used for cancer cure for high blood pressure alcohol and valium relief from constipation liver infection treatment cialis soft zantac medication help sleep problems all natural antibiotics order medication without prescription sleep problems free hypnotherapy gaining muscle mass cheap viagra order online natural help for pain how to buy viagra drug price celebrex information otc diuretic levitra 10 mg buy medicine online pets products relief foot pain cialis without prescription med care cheapest generic cialis rapid hair loss pain medications generic side effects meds without prescriptions cat anxiety buy simplicef natural cure arthritis effects of high blood pressure lowest price generic viagra how to get birth control new breast cancer drug buy topamax blood pressure meds when are beta blockers prescribed how to get pain meds order fosamax online viagra name order viagra viagra cialis cat's eye health how to relieve lower back pain treating ear infections diazapan is valium online pain doctors high blood pressure in elderly medication to stop smoking wellbutrin dosages diabetes blood sugar levels weight loss diet pill side effects of prescribed pain pills drug list high blood pressure buy cialis online in usa ultram cost how to help osteoporosis how to use clomid discount brand viagra wellbutrin cymbalta buy pills without a prescription buy pain medicine online tab tramadol depression symptoms treatment how levitra work hypertension medications beta blockers prevent premature ejaculation xanax interactions with other medicines purchase medicine on line does alli work xenical mexico prescriptions buy sumycin uy prescription medication without a prescription ambien cost methocarbamol effects cheap beta blockers cats bladder reduce cholesterol naturally metformin tablet scabies medicine breast enhancer pills body building over 50 order viagra cheap zestril medication how to buy prescription medications online pharma kamagra drugs depression ear infection symptoms big muscle controlling blood pressure pain meds and pregnancy buy diazepam without prescription skin allergies antibiotic zoloft buy weight loss nutrition program Buy Cialis breast increase meds without prescriptions blood clots medical edema treatment for flu best hangover remedy diabetes drugs