How to test a jSeduite Web Service

The usual test framework (jUnit) is not automatically suitable for testing Web Services: it allows you to test the POJO classes you've written (as annotated Java classes). This mechanism doesn't go through the full Web Service stack (e.g. SOAP marshalling, un-marshalling, exception renaming).

To go through this stack, we have to manually define a web service client which “proxify” the real web service, and then implement the test suite for this proxy.

Writing a local proxy

  1. Right click on the project root, New / Web Service Client
    • create a new Java Applicationinside the jUnit folder
    • Use the ServiceNameTest naming convention.
  2. Rename the Main class into ServiceNameProxy
  3. Right click on the project root, New / Web Service Client.
    • Use the remote WSDL location field ( http://localhost:8080/jSeduite/… )
  4. For each operation defined inside the Web Service, define a local method inside the ServiceNameProxy class
    • Just drag'n drop the current operation from the Web Service References folder
    • Each method will throw an Exception if the originial Web Service operation throws an exception.

Remarks: the class loading mechanisms seems weird, and the web service package is not found if you try to import it at the beginning of the file. ⇒ Web have to prefix each service (resp. port) with the full namespace (i.e. package in Java vocabulary) prefix. I know it's a burden …

Writing a Test Case & a Test Suite

  1. Inside the ServiceNameTest project, right click on Test Package
    • Choose New / Test for Existing Class.
    • Select the ServiceNameProxy class, and select Finish to generate the test case.
  2. Choose the jUnit 4.x framework
  3. Clean up the generated test case (delete meaningless constructions), include the licence header, …
  4. Implements your tests ! LOL

TestSuite: A TestSuite is a jUnit construction which run all tests defined in an existing package. You can create a test suite by creating a New / Test Suite … and select your test package.

Running the Test Suite

  1. Right click on the ServiceNameTest project root, and then choose Test.
  2. The JUnit Tests Results window will pop, describing tests results

Example

cookbook/test-ws.txt · Last modified: 2009/05/13 14:19 by mosser
CC Attribution-Noncommercial-Share Alike 3.0 Unported www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0