harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew Zhang" <zhanghuang...@gmail.com>
Subject Re: [classlib] jetty based tests
Date Tue, 23 May 2006 04:55:53 GMT
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 <stepan.mishura@gmail.com> 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 (t.p.ellison@gmail.com)
> > IBM Java technology centre, UK.
> >
> > ---------------------------------------------------------------------
> > Terms of use : http://incubator.apache.org/harmony/mailing.html
> > To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> > For additional commands, e-mail: harmony-dev-help@incubator.apache.org
> >
> >
>
>
> --
> Thanks,
> Stepan Mishura
> Intel Middleware Products Division
>
> ------------------------------------------------------
> Terms of use : http://incubator.apache.org/harmony/mailing.html
> To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
> For additional commands, e-mail: harmony-dev-help@incubator.apache.org
>
>


-- 
Andrew Zhang
China Software Development Lab, IBM

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message