|
Hi Aaron, You might want to look over: Unit Test Your Struts Application http://www.onjava.com/lpt/a/5210 WSUnit - The Web Services Testing Tool https://wsunit.dev.java.net/ Java Testing and Design - free pdf of the book, has updated website http://www.theserverside.com/tt/books/prenticeHall/JavaTestingAndDesign/index.tss Joe Sam Joe Sam Shirah - http://www.conceptgo.com conceptGO - Consulting/Development/Outsourcing Java Filter Forum: http://www.ibm.com/developerworks/java/ Just the JDBC FAQs: http://www.jguru.com/faq/JDBC Going International? http://www.jguru.com/faq/I18N Que Java400? http://www.jguru.com/faq/Java400 ----- Original Message ----- From: "albartell" <albartell@xxxxxxxxx> To: "'Java Programming on and around the iSeries / AS400'" <java400-l@xxxxxxxxxxxx> Sent: Tuesday, June 27, 2006 2:37 PM Subject: JUnit for webservices - critique me
Ok. So today I made some changes to my iSeries software and went through
my
usual motions of testing it thoroughly. When I was done I realized I
spent
about 2 hours cutting and pasting various xml documents into my GUI Web Service Unit Tester (http://mowyourlawn.com/blog/?p=17). It was then I realized I needed to "enhance" my method of doing humdrum testing so I ventured into the JUnit world. I have read about JUnit but have never implemented it's practices because I have had other programmatical means
to
test various processes, but they are much more manual than what I believe JUnit has to offer. I have put together what I understand to be JUnits approach to testing if
a
web service has executed successfully. I have done both tests for valid completion and also tests for exceptions (say errors). The basic concept
is
that I execute an HTTP POST against a web service on the iSeries using a local document as the POST content. The response I receive from the POST
is
then compared to another local document to see if the expected results
were
received. Here is my main class that I execute in Eclipse by doing a Run As -> JUnit Test import junit.framework.Test; import junit.framework.TestSuite; public class AllTests { public static void main(String[] args) { } public static Test suite() { TestSuite suite = new TestSuite("Web service testing"); //$JUnit-BEGIN$ suite.addTestSuite(Webservices.class); //$JUnit-END$ return suite; } } -----Here is the Webservices.java file----- import java.io.IOException; import java.net.ConnectException; import java.net.MalformedURLException; import junit.framework.TestCase; import org.junit.After; import org.junit.Before; import org.junit.Test; import util.FileControl; import util.HttpUtil; public class Webservices extends TestCase { String svrUrl = "http://172.29.134.41:8181/myrxs/"; public Webservices(String arg0) { super(arg0); } @Before protected void setUp() throws Exception { super.setUp(); } @After protected void tearDown() throws Exception { super.tearDown(); } @Test public void test_rxs5_t1() { System.out.println("Running...rxs5_t1"); try { String fullUrl = svrUrl + "rxs5"; String postContent = FileControl.readFileToString("xml/reqdocs/rxs5_t1.xml"); String contentType = "text/xml"; String soapAction = ""; String actual = HttpUtil.post(fullUrl, postContent,
contentType,
soapAction); String expected = FileControl.readFileToString("xml/rspdocs/rxs5_t1.xml"); assertEquals("Response document not as expected.", expected, actual); } catch (ConnectException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } @Test public void test_rxs5_t2() { System.out.println("Running...rxs5_t2"); try { String fullUrl = svrUrl + "rxs5"; String postContent = FileControl.readFileToString("xml/reqdocs/rxs5_t2.xml"); String contentType = "text/xml"; String soapAction = ""; String actual = HttpUtil.post(fullUrl, postContent,
contentType,
soapAction); String expected = FileControl.readFileToString("xml/rspdocs/rxs5_t2.xml"); assertEquals("Response document not as expected.", actual.startsWith(expected)); } catch (ConnectException e) { e.printStackTrace(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } } Am I going in the right direction? Aaron Bartell http://mowyourlawn.com
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2025 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.