Hello, all ,

I perfer to embed jetty in our test code to avoid external server in some
test cases.

"I'm not against 'jetty based tests' but I'd prefer to separate such tests."


Stepan, If jetty is embedded in our test case code, I think it's unnecessary
still to seperate such tests, since there's no external dependency at all.

Consider following test case from URLConnectionTest.java, luni module:


/**
 * @tests java.net.URLConnection#setUseCaches(boolean)
 */
public void test_setUseCachesZ() throws MalformedURLException, IOException
{
 // Regression for HARMONY-71
 URLConnection u = new URLConnection(new URL("http://www.apache.org";)) {
     public void connect() {
         connected = true;
     }
 };

 u.connect();
 try {
  u.setUseCaches(true);
  fail("Assert 0: expected an IllegalStateException");
 } catch (IllegalStateException e) {
  // expected
 }
}
If we revise the test case  with Jetty embedded, as following code:

public class JettySample extends TestCase {

private HttpServer server = null;

protected void setUp() throws Exception {
 server = new HttpServer();
 SocketListener listener = new SocketListener();
 listener.setPort(80);
 server.addListener(listener);
 HttpContext context = new HttpContext();
 context.setContextPath("/");
 // currently, a folder named "webapps" is put in the project root
directory
 // We could put this folder in project "support" if we decide to embed
jetty
 // and configure the resource base sth. like "support/resource/...".
 context.setResourceBase("webapps");
 context.addHandler(new ResourceHandler());
 server.addContext(context);
 server.start();
}

protected void tearDown() throws Exception {
 if (null != server) {
  server.stop();
 }
}

/**
 * @tests java.net.URLConnection#setUseCaches(boolean)
 */
public void test_setUseCachesZ() throws MalformedURLException, IOException
{
 // Regression for HARMONY-71
 URLConnection u = new URLConnection(new URL("http://localhost";)) {
     public void connect() {
         connected = true;
     }
 };
 u.connect();
 try {
  u.setUseCaches(true);
  fail("Assert 0: expected an IllegalStateException");
 } catch (IllegalStateException e) {
  // expected
 }
}
}

People could run the revised test case without any external server. And it
costs us two jars (or.mortbay.jetty.jar, commons-logging.jar) and about
300ms overhead (if log info is disabled).

Any suggestion or comment ?

Thanks!

On 5/22/06, Stepan Mishura <[EMAIL PROTECTED]> wrote:

On 5/19/06, Tim Ellison wrote:
>
> Stepan Mishura wrote:
> <snip>
> > I'm OK only if we separate tests with Jetty from common test suite
run.
>
> Why?


Because each external dependency complicates 'normal' test suite run ( I
don't want to face with situation when to run Harmony test suite I have to
configure and run 20 different external servers even they are easy
configurable). As far as I remember we agreed to use mock objects - so
let's
use them! For example, in this case there is no need in jetty server.

I'm not against 'jetty based tests' but I'd prefer to separate such tests.

Thanks,
Stepan.

Regards,
> Tim
>
> --
>
> Tim Ellison ([EMAIL PROTECTED])
> IBM Java technology centre, UK.
>
> ---------------------------------------------------------------------
> Terms of use : http://incubator.apache.org/harmony/mailing.html
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>


--
Thanks,
Stepan Mishura
Intel Middleware Products Division

------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




--
Andrew Zhang
China Software Development Lab, IBM

Reply via email to