views:

70

answers:

4

I'm very new to JUnit, but I want to set up some tests which does the following..

  1. Tests a range of server to server API calls - verifying the responses are correct - I can do that fine.

  2. Open a web page, enter data onto it and verify what happens on submit - This I am struggling with. Is it even possible?

I am thinking that I could call a web page using a server side http web request, but I'm not sure how I can interact with the site itself, i.e. enter data into the forms.

Any thoughts?

Thanks

Steve

+5  A: 

You could use Selenium for this. I suggest you use the version 2 which is currently in development and should have a beta available soon (alphas are already available).

Joachim Sauer
+1 for recommending version 2. It is waaaay better than previous releases.
ponzao
+3  A: 

Have a look at Selenium, it's a system to test web applications (and de facto websites) you can write all your tests in java. There is an ather project named Tellurium, based on Selenium but Tellurium works with groovy and a DSL, it might be easier to handle at first.

How does this works ?

  • First you create tests in java (Selenium) or groovy (Tellurium)
  • Then you start your tests. It will work with your web browser. The application will interact with your browser to test every inch of your application (as you coded it)
  • At the end it give you a report about yours tests, just as JUnit do.
Colin Hebert
Great, thanks Colin (and Joachim), I will give Selenium a try.
A: 

You can also exploit the nature of the web. There's no real reason to render a form, fill it out and submit it to test the form processing code. The display of the form is one HTTP request, and the submission is another. It's perfectly reasonable to test form submission code by mocking up what a browser would send and asserting that it's handled correctly.

You do need to make sure that the form rendering and submission test code are in sync, but you don't necessarily need a full integration for this either.

There are tools that allow testing without booting up a browser... one that springs to mind is HTMLUnit (and there are others). If you find that Selenium is a pain to write, or the tests brittle or flakey, look for simpler tools like this.

ndp
A: 

I suggest you to try the Robot Framework. This is an open source testing framework developed by engineers in Nokia Siemens Networks.

It is primarily built on python and the Selenium testing libraries. It also includes support for testing Java/J2EE server side code through Jython libraries. I personally use it in my work sometimes, and writing a test case is just as easy as describing an end-to-end flow through the use of Keywords (most of required ones are already inbuilt). You could go ahead and give this a shot if you find Selenium a li'l tough to work with. The Robot framework provides a fairly simple abstraction over raw selenium, coupled with the power to make Java/J2EE server-side calls too.

Regards,
Nagendra U M

Nagendra U M