Skip to search.

Breaking News Visit Yahoo! News for the latest.

×Close this window

junit · JUnit, the Java unit testing framework written by Kent Beck and Erich Gamma.

The Yahoo! Groups Product Blog

Check it out!

Group Information

  • Members: 31224
  • Category: Java
  • Founded: Nov 6, 2000
  • Language: English
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Message search is now enhanced, find messages faster. Take it for a spin.

Messages

Advanced
Messages Help
Messages 9250 - 9279 of 24384   Oldest  |  < Older  |  Newer >  |  Newest
Messages: Show Message Summaries Sort by Date ^  
#9250 From: "Ilja Preuss" <preuss@...>
Date: Mon Sep 1, 2003 10:55 am
Subject: RE: Interfaces and Mock Objects
ipreussde
Send Email Send Email
 
J. B. Rainsberger wrote:
> Next, I am experimenting with the following Java
> implementation pattern.
> A refactoring, I think.
>
>     * Replace private/public separation with interface/implementation
> separation.
>
> In other words, rather than make methods private, which can hurt
> testing, extract a client interface and ship it to the client. Hide
> creating instances behind factories. In other words, do like JDBC,
> JMS, EJB...
>
> I like it. Thoughts?

Sounds a lot like the Interface Segregation Principle in action. :)

Regards, Ilja

#9251 From: "J. B. Rainsberger" <jbrains@...>
Date: Mon Sep 1, 2003 4:50 pm
Subject: Re: Interfaces and Mock Objects
nails762
Send Email Send Email
 
Ilja Preuss wrote:

> J. B. Rainsberger wrote:
>  > Next, I am experimenting with the following Java
>  > implementation pattern.
>  > A refactoring, I think.
>  >
>  >     * Replace private/public separation with interface/implementation
>  > separation.
>  >
>  > In other words, rather than make methods private, which can hurt
>  > testing, extract a client interface and ship it to the client. Hide
>  > creating instances behind factories. In other words, do like JDBC,
>  > JMS, EJB...
>  >
>  > I like it. Thoughts?
>
> Sounds a lot like the Interface Segregation Principle in action. :)

I didn't know what name it had. Reference, please?
--
J. B. Rainsberger,
Diaspar Software Services
http://www.diasparsoftware.com :: +1 416 791-8603
Let's write software that people understand

#9252 From: Mike Clark <mike@...>
Date: Mon Sep 1, 2003 5:17 pm
Subject: Re: Interfaces and Mock Objects
clarkware
Send Email Send Email
 
J. B. Rainsberger wrote:

>>
>>Sounds a lot like the Interface Segregation Principle in action. :)
>
>
> I didn't know what name it had. Reference, please?


http://www.objectmentor.com/resources/articles/isp.pdf

Or, as you're always so fond of saying: Please Google "Interface
Segregation Principle".

:-)

Mike

#9253 From: Bob Koss <koss@...>
Date: Mon Sep 1, 2003 6:24 pm
Subject: Re: Interfaces and Mock Objects
koss@...
Send Email Send Email
 
>
>>>
>>> Sounds a lot like the Interface Segregation Principle in action. :)
>>

I don't see it that way. ISP says clients should only have a source code
dependency upon interfaces that they use. J.B. is suggesting taking private
methods (which have only one client - the class itself) and putting them in
another class - where they may or may not have more clients.

I suppose if I squint just the right way I could argue that it's ISP.


--
Robert Koss, Ph.D.     | Training, Mentoring, Contract Development
Senior Consultant      | Object Oriented Design, C++, Java
www.objectmentor.com   | Extreme Programming

#9254 From: Eric Armstrong <eric.armstrong@...>
Date: Mon Sep 1, 2003 11:46 pm
Subject: Ordering of tests -- indispensible feature??
ericsilverlight
Send Email Send Email
 
I'm finding a need to get either forward or backward
order in my test methods, and it's beginning to look
like a pretty indispensible feature.

Each test is independent of all the others, of course,
so it doesn't particularly matter which one is rum first
when they all succeed. It matters when one fails.

Let's say that testB uses functions that are tested in testA.

During development, I'll be coding testA first. When that
passes, I'll move to testB.

But tests take time. And as the number of tests grows, it
takes longer and longer to get to the last test on the list.
So testing in reverse order speeds things up during development.
(Or simply running the last test, rather than all of them.)

But when running the full suite of tests, it's helpful to
run them in the original order -- because sometimes a regression
causes a test to fail which was passing earlier, and it's
good to discover such violated assumptions.

So there's a tension between wanting to speed things up
and wanting to verify that previously valid assumptions
still hold.

The only way I can see to satisfy both goals is to allow
tests to run either from first to last, or from last to
first.

Any other ideas?

#9255 From: "J. B. Rainsberger" <jbrains@...>
Date: Tue Sep 2, 2003 12:06 am
Subject: Re: Ordering of tests -- indispensible feature??
nails762
Send Email Send Email
 
Eric Armstrong wrote:

> I'm finding a need to get either forward or backward
> order in my test methods, and it's beginning to look
> like a pretty indispensible feature.
>
> Each test is independent of all the others, of course,
> so it doesn't particularly matter which one is rum first
> when they all succeed. It matters when one fails.
>
> Let's say that testB uses functions that are tested in testA.

Let's instead say that TestB collaborates with lightweight objects that
provide predictable results according to the behavior we expect of A.

> During development, I'll be coding testA first. When that
> passes, I'll move to testB.
>
> But tests take time. And as the number of tests grows, it
> takes longer and longer to get to the last test on the list.

How long is long? How many tests? What's your test throughput 100/s?
200/s? Less?

> So testing in reverse order speeds things up during development.
> (Or simply running the last test, rather than all of them.)
>
> But when running the full suite of tests, it's helpful to
> run them in the original order -- because sometimes a regression
> causes a test to fail which was passing earlier, and it's
> good to discover such violated assumptions.
>
> So there's a tension between wanting to speed things up
> and wanting to verify that previously valid assumptions
> still hold.
>
> The only way I can see to satisfy both goals is to allow
> tests to run either from first to last, or from last to
> first.

Another option is to execute only the current suite while working on the
behavior under test, then execute the full suite when you think you have
the behavior under test working.

> Any other ideas?

Yes. Write faster tests. I usually get up to about 1500 before I start
to notice a break in my rhythm. If I notice a break in my rhythm before
I hit 1500 tests, then I fix the tests.
--
J. B. Rainsberger,
Diaspar Software Services
http://www.diasparsoftware.com :: +1 416 791-8603
Let's write software that people understand

#9256 From: David Postill <david.postill@...>
Date: Mon Sep 1, 2003 5:19 pm
Subject: Re: Interfaces and Mock Objects
davidpostill
Send Email Send Email
 
On Mon, 01 Sep 2003 12:50:08 -0400, "J. B. Rainsberger" <jbrains@...>
wrote:

| Ilja Preuss wrote:

<snip>

| > Sounds a lot like the Interface Segregation Principle in action. :)
|
| I didn't know what name it had. Reference, please?


http://www.objectmentor.com/resources/articles/isp.pdf The Interface
Segregation Principle

<davidp />

--
David Postill-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, 01 Sep 2003 12:50:08 -0400, "J. B. Rainsberger" <jbrains@...>
wrote:

| Ilja Preuss wrote:

<snip>

| > Sounds a lot like the Interface Segregation Principle in action. :)
|
| I didn't know what name it had. Reference, please?


http://www.objectmentor.com/resources/articles/isp.pdf The Interface
Segregation Principle

<davidp />

- --
David Postill

-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0.2 - not licensed for commercial use: www.pgp.com
Comment: Get key from pgpkeys.mit.edu:11370

iQA/AwUBP1N/d3xp7q1nhFwUEQIYDQCgmjSZyTwDHVjWtEjaG077bzj098EAoIhV
3AQ0RTjZ5ukFyOxlY0WVVdYr
=3AcL
-----END PGP SIGNATURE-----

#9257 From: Anbarasan Chandramohan <a_c_mohan@...>
Date: Mon Sep 1, 2003 4:29 am
Subject: Problem using JWebUnit
a_c_mohan
Send Email Send Email
 
Hi All,

    We are using JWebUnit for testing Web Applications. Jwebunit is internally
using JUnit for assertions.
    This code is for testing whether a table is present in a web page and
clicking a link present in the table.

    public class Bug9482TestScript extends WebTestCase
    {
    public Bug9482TestScript(String name)
    {
       super(name);
    }
    public void setUp()
    {
       getTestContext().setBaseUrl("http://localhost:1760/myPage");
    }
    public void testMessage()
    {
       beginAt("/");
       setFormElement("uid", "System");
       setFormElement("password", "Manager");
       submit("Submit");
       gotoRootWindow();
       assertLinkPresentWithText("Learning Activities");
       clickLinkWithText("Learning Activities");
       gotoRootWindow();
       assertTablePresent("mySummary");
       assertTextInTable("mySummary","Blended Activity");
       assertTextInTable("mySummary","1001");
       //clickLinkWithText("1001");

       I am able to find the link text present in the table. But if i try to
click the link, it's throwing this Runtime Exception.
If anybody knows the solution, please send to our group.
Exception:
      java.lang.RuntimeException: com.meterware.httpunit.ScriptException: Script
'// fill the form if it is cacheable
if (typeof form_cacher != 'undefined')
     form_cacher.fillFromUrl(document.location.href);' failed: ConversionError:
The undefined value has no properties. (httpunit; line 162)
  at
com.meterware.httpunit.javascript.JavaScript$JavaScriptEngine.handleScriptExcept\
ion(JavaScript.java:182)
  at
com.meterware.httpunit.javascript.JavaScript$JavaScriptEngine.executeScript(Java\
Script.java:119)
  at
com.meterware.httpunit.scripting.ScriptableDelegate.runScript(ScriptableDelegate\
.java:55)
  at
com.meterware.httpunit.ScriptFilter.getTranslatedScript(ScriptFilter.java:140)
  at com.meterware.httpunit.ScriptFilter.endElement(ScriptFilter.java:121)
  at org.cyberneko.html.HTMLTagBalancer.endElement(Unknown Source)
  at org.cyberneko.html.HTMLScanner$SpecialScanner.scan(Unknown Source)
  at org.cyberneko.html.HTMLScanner.scanDocument(Unknown Source)
  at org.cyberneko.html.HTMLConfiguration.parse(Unknown Source)
  at org.cyberneko.html.HTMLConfiguration.parse(Unknown Source)
  at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
  at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
  at com.meterware.httpunit.NekoHTMLParser.parse(NekoHTMLParser.java:49)
  at com.meterware.httpunit.HTMLPage.parse(HTMLPage.java:249)
  at com.meterware.httpunit.WebResponse.getReceivedPage(WebResponse.java:918)
  at com.meterware.httpunit.WebResponse.access$100(WebResponse.java:49)
  at com.meterware.httpunit.WebResponse$Scriptable.load(WebResponse.java:572)
  at
com.meterware.httpunit.javascript.JavaScript$Window.initialize(JavaScript.java:3\
90)
  at com.meterware.httpunit.javascript.JavaScript.run(JavaScript.java:80)
  at
com.meterware.httpunit.javascript.JavaScriptEngineFactory.associate(JavaScriptEn\
gineFactory.java:46)
  at com.meterware.httpunit.FrameHolder.updateFrames(FrameHolder.java:82)
  at com.meterware.httpunit.WebWindow.updateFrameContents(WebWindow.java:184)
  at com.meterware.httpunit.WebClient.updateFrameContents(WebClient.java:472)
  at com.meterware.httpunit.WebWindow.updateWindow(WebWindow.java:167)
  at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:111)
  at com.meterware.httpunit.WebWindow.sendRequest(WebWindow.java:99)
  at
com.meterware.httpunit.WebRequestSource.submitRequest(WebRequestSource.java:204)
  at
com.meterware.httpunit.WebRequestSource.submitRequest(WebRequestSource.java:195)
  at com.meterware.httpunit.WebLink.click(WebLink.java:86)
  at net.sourceforge.jwebunit.HttpUnitDialog.submitRequest(Unknown Source)
  at net.sourceforge.jwebunit.HttpUnitDialog.clickLinkWithText(Unknown Source)
  at net.sourceforge.jwebunit.WebTester.clickLinkWithText(Unknown Source)
  at net.sourceforge.jwebunit.WebTestCase.clickLinkWithText(Unknown Source)
  at
net.sourceforge.jwebunit.sample.Bug9482TestScript.testMessage(Bug9482TestScript.\
java:32)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav\
a:25)

  at net.sourceforge.jwebunit.HttpUnitDialog.submitRequest(Unknown Source)
  at net.sourceforge.jwebunit.HttpUnitDialog.clickLinkWithText(Unknown Source)
  at net.sourceforge.jwebunit.WebTester.clickLinkWithText(Unknown Source)
  at net.sourceforge.jwebunit.WebTestCase.clickLinkWithText(Unknown Source)
  at
net.sourceforge.jwebunit.sample.Bug9482TestScript.testMessage(Bug9482TestScript.\
java:32)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav\
a:25)


Thanks in Advance,
A.Chandramohan


---------------------------------
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software

[Non-text portions of this message have been removed]

#9258 From: "José" Vicente "Núñez" Zuleta <josevnz@...>
Date: Tue Sep 2, 2003 3:54 am
Subject: Problems generating the Javadoc for Junit tests
josevnz
Send Email Send Email
 
Greetings,

I got the following error while generating the Junit
tests javadoc:

doc:
   [javadoc] Generating Javadoc
   [javadoc] Javadoc execution
   [javadoc] Loading source files for package
cvebrowser.dictionary.data...
   [javadoc] Loading source files for package
cvebrowser.dictionary.data.net...
   [javadoc] Loading source files for package
cvebrowser.dictionary.data.parser...
   [javadoc] Loading source files for package
cvebrowser.dictionary.data.persistence...
   [javadoc] Loading source files for package
cvebrowser.dictionary.data.persistence.util...
   [javadoc] Loading source files for package
cvebrowser.util.parser...
   [javadoc] Loading source files for package
cvebrowser.test...
   [javadoc] Constructing Javadoc information...
   [javadoc]
/home/josevnz/sourceforge/cvebrowser/src/cvebrowser/test/RunAllDownloadTests.jav\
a:3:
package junit.framework does not exist
   [javadoc] import junit.framework.TestCase;
   [javadoc]                        ^
   [javadoc]
/home/josevnz/sourceforge/cvebrowser/src/cvebrowser/test/RunAllDownloadTests.jav\
a:4:
package junit.framework does not exist
   [javadoc] import junit.framework.Test;
   [javadoc]                        ^
   [javadoc]
/home/josevnz/sourceforge/cvebrowser/src/cvebrowser/test/RunAllDownloadTests.jav\
a:5:
package junit.framework does not exist
   [javadoc] import junit.framework.TestSuite;

But i'm able to compile the test cases and run them
without a problem; Also the javadoc is generated for
the other clases without a problem.

I'm sharing the same classpath definition for the
javadoc and test compilation:

   <path id="path.classpath">
  	 <fileset dir="${jar.basedir}">
		 <include name="${jar.jdbc}"/>
		 <include name="${jar.log4j}"/>
		 <include name="${jar.getopt}"/>
	 </fileset>
	 <pathelement location="${build}" />
   </path>

       <javadoc
          sourcepath="${src}"
          destdir="${dist}/doc/javadoc"
          packageList="PackageList.txt"
          package="true"
          version="true"
          use="true"
          author="true"
       ...>
	  <classpath>
	 	 <path refid="path.classpath"/>
		 <path location="${test}"/>
		 <path location="${build}"/>
	  </classpath>
</javadoc>

My "PackageList.txt" contains all the appropiate
packages (each one on a separate line).

I'm using ant 1.5.2.

Does anyone have experienced this problem?

Thanks in advance.

#9259 From: Eric Armstrong <eric.armstrong@...>
Date: Tue Sep 2, 2003 5:14 am
Subject: Re: Ordering of tests -- indispensible feature??
ericsilverlight
Send Email Send Email
 
I should have mentioned that I'm using the javadoc
doclet APIs, which imposes extreme limits on the
amount of serious "unit testing" I can do.

So I'm effectively using JUnit to do integration
tests, and working in the debugger a lot of time,
where the integration test lets me expose problems
I can then debug on.

What I've settled on at the moment is:
    a) Put the most recent test at the top of the
       list, and put a breakpoint at the start of
       the first test.

    b) When the test fails in semi-normal fashion,
       exit the debugger and poke around to find
       the problem.

    c) If it fails in some egregious manner, let
       all of the tests run to see if I can isolate
       it a little better.

    d) When it passes, move it to the bottom of the
       list.

    e) Run all of the tests whenever I take a break,
       so they're there to look at when I get back.

This is a lot less pure than having lots of tests,
but being unable to unit test the basic library
functions (no exposed constructors, only interfaces)
has created a situation where it's difficult to control
the depth of the bugs I see -- they tend to be deep,
and result basic design revisions.

I've isolated the problem as much as possible with
non-dependent infrastructure that I've tested to my
hearts content -- and which naturally doesn't produce
any "interesting" bugs, I'm happy to say.

I'm not sure how many others find themselves in
situations like this. But since there are no concrete
classes in the library I'm using, there is absolutely
no way to create proxy objects with any assurance that
the replicate the behavior that the library exhibits.

So it seemed to me that this might be an unusual case
where "ordering" was desirable -- for time's sake,
rather than for the correctness of the result.

Or maybe, now that I've characterized the problem a
little further, you and other helpful folks on this
list will be able to better assist me in finding the
"one true path" to testing nirvana.
:_))

J. B. Rainsberger wrote:

> Eric Armstrong wrote:
>
>
>>I'm finding a need to get either forward or backward
>>order in my test methods, and it's beginning to look
>>like a pretty indispensible feature.
>>
>>Each test is independent of all the others, of course,
>>so it doesn't particularly matter which one is rum first
>>when they all succeed. It matters when one fails.
>>
>>Let's say that testB uses functions that are tested in testA.
>
>
> Let's instead say that TestB collaborates with lightweight objects that
> provide predictable results according to the behavior we expect of A.
>
>
>>During development, I'll be coding testA first. When that
>>passes, I'll move to testB.
>>
>>But tests take time. And as the number of tests grows, it
>>takes longer and longer to get to the last test on the list.
>
>
> How long is long? How many tests? What's your test throughput 100/s?
> 200/s? Less?
>
>
>>So testing in reverse order speeds things up during development.
>>(Or simply running the last test, rather than all of them.)
>>
>>But when running the full suite of tests, it's helpful to
>>run them in the original order -- because sometimes a regression
>>causes a test to fail which was passing earlier, and it's
>>good to discover such violated assumptions.
>>
>>So there's a tension between wanting to speed things up
>>and wanting to verify that previously valid assumptions
>>still hold.
>>
>>The only way I can see to satisfy both goals is to allow
>>tests to run either from first to last, or from last to
>>first.
>
>
> Another option is to execute only the current suite while working on the
> behavior under test, then execute the full suite when you think you have
> the behavior under test working.
>
>
>>Any other ideas?
>
>
> Yes. Write faster tests. I usually get up to about 1500 before I start
> to notice a break in my rhythm. If I notice a break in my rhythm before
> I hit 1500 tests, then I fix the tests.

#9260 From: "Ilja Preuss" <preuss@...>
Date: Tue Sep 2, 2003 8:54 am
Subject: RE: Interfaces and Mock Objects
ipreussde
Send Email Send Email
 
Bob Koss wrote:
>>>> Sounds a lot like the Interface Segregation Principle in action. :)
>>>
>
> I don't see it that way. ISP says clients should only have a
> source code dependency upon interfaces that they use. J.B. is
> suggesting taking private methods (which have only one client
> - the class itself) and putting them in another class - where
> they may or may not have more clients.

As I understand it, he was suggesting something else in the post I
replied to. Namely making the method public without moving it, but
extracting an interface for the client which doesn't contain the
formerly private method. ISP, so it seems to me.

Regards, Ilja

#9261 From: "Ilja Preuss" <preuss@...>
Date: Tue Sep 2, 2003 8:52 am
Subject: RE: Interfaces and Mock Objects
ipreussde
Send Email Send Email
 
Mike Clark wrote:
> http://www.objectmentor.com/resources/articles/isp.pdf

Or http://c2.com/cgi/wiki?InterfaceSegregationPrinciple



> Or, as you're always so fond of saying: Please Google "Interface
> Segregation Principle".

ROFL

Regards, Ilja

#9262 From: "J. B. Rainsberger" <jbrains@...>
Date: Tue Sep 2, 2003 2:29 pm
Subject: Re: Interfaces and Mock Objects
nails762
Send Email Send Email
 
Ilja Preuss wrote:

> Mike Clark wrote:
>  > http://www.objectmentor.com/resources/articles/isp.pdf
>
> Or http://c2.com/cgi/wiki?InterfaceSegregationPrinciple
>
>  > Or, as you're always so fond of saying: Please Google "Interface
>  > Segregation Principle".
>
> ROFL

Has the Master not earned the right to expect the Student to pour the
tea? :)

I will remember to use Google.
I will remember to use Google.
I will remember to use Google.

[I typed those lines out myself -- no copy-and-paste, I swear!]
--
J. B. Rainsberger,
Diaspar Software Services
http://www.diasparsoftware.com :: +1 416 791-8603
Let's write software that people understand

#9263 From: "Thomas Robbs" <thomas.robbs@...>
Date: Tue Sep 2, 2003 2:55 pm
Subject: RE: Re: HTTP Testing - Local and Remote
trobbs2
Send Email Send Email
 
Thanks for the reply, Paul.  Sorry I didn't get to it earlier but my
Email reader decided to file this separately and I've missed it until
now.

In a nutshell, my tests are functional in nature and not UnitTests.
They are closer to CustomerTests as well given that I want to simulate
user interaction with the applications (which are accessible via the web
server).  The nature of our product means that I don't think I need the
overhead of using Cactus.  Our product can currently run on its own on a
set-top box or within its own container on a server.  As such, our
functional tests are effectively the same and we'd like to reuse these
accordingly, and build upon them for future customer scenarios.

Did you get a chance to see my follow-up Email to my original post?  I
think I have an idea for how to solve this, but I wanted some validation
on it.  Hopefully I'll get to go ahead and JustTryIt, but I'm currently
tasked with another project and won't be able to get to it as
immediately as I would like.

Thanks again for the reply, and sorry if this is too far OT for this
group.

Cheers,

Tom

-----Original Message-----
From: Paul Christmann [mailto:java-junit@...]
Sent: August 27, 2003 11:03 AM

I've also wanted similar functionality as you describe, and have done it
using ant, junit, tomcat and cactus.  (And my own WebServer java code.
Yikes.....).  (I don't consider this "unit" testing, per se.  But I do
consider it a reasonable problem, and one that I solved with "unit"
testing tools.)

So here's a bunch of thoughts which I hope provide some insights into
what I did to solve a similar problem:

I wanted to test HTTP communication with a server, and test excercising
remote functionality.  At first, I thought they were the same tests, and
I only tried to excercise the remote functionality.  I quickly learned
that this was too hard - because a problem with a malformed HTTP message
was very hard to diagnose.  So, I split the problem into two:

1) Test HTTP Communication with a server.  I now define this as meaning:
can my client generate an appropriate http message, with the correct
headers and body?  Can the server interpret an http message, reading
http headers correctly?

This is something I consider "unit" tests.

1a) Testing the server side is pretty easy using cactus.  I use the
FilterTestCase, as all of our Http "interpretation" on the server is
handled in a single Filter.  So all I have to do is test that single
filter to make sure Http headers are interpreted appropriately.

1b) Testing the client side is a little harder, and required me to
eventually mock a web server for the client to use just to trap http
headers.  I'm not particularly fond of this solution.
Essentially, the build launches its own web server, the client code
talks to it, and then the test code verifies that the web server
received expected data.

2) Test remote method invocations: If I ask the server to do something,
does it do the right thing?

This is something I consider "functional" testing.

(In our case, all request/responses are wrapped as Java objects.  So
test code deals only with Java objects, without any knowledge of the
fact that perhaps a remote server was called to handle the request.  The
test code just creates and verifies java objects)

2a) I have ant build file that will run a bunch of JUnit tests with a
URL provided as input.  The test java code opens a connection to the
provided URL and requests something (the actual opening of the
URLConnedtion is hidden from the test code).  The test java code then
verifies the response.

2b) The ant build file will (by default) launch its own version of
Tomcat first.  The test will run entirely on a single machine;
launch Tomcat with an appropriate web application and the JUnit tests
talk to it.  This (getting tomcat started up) proved to be a little
tricky, but quite doable.

2c) Alternatively, by changing the build properties, the same JUnit test
will run against an already running server (locally or remotely, doesn't
matter).  In our case, we use that to verify a deployed/staging
environment.

I'm going to skip posting details of code and build files unless
anyone actually thinks it would be useful.

Thomas Robbs wrote:
> Greetings...
>
> I'm finding myself in a situation where I would like to create the
> following type of test case:
>
> - testing a web service via HTTP - default testing of the service
> would require that the HTTP server is started up on the local machine
>  - an additional way of executing the test would be to have the same
>  HTTP based tests execute against an assumed host/port that is
> already running the HTTP server w/ the service.
--
PC

Paul Christmann
Prior Artisans, LLC
mailto:paul@...
504-587-9072







Yahoo! Groups Sponsor
ADVERTISEMENT




To unsubscribe from this group, send an email to:
junit-unsubscribe@yahoogroups.com


Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.

#9264 From: "Chappell, Simon P" <simon.chappell@...>
Date: Tue Sep 2, 2003 3:06 pm
Subject: RE: Classloader troubles on Mac OS X
simon.chappell@...
Send Email Send Email
 
A couple of things leap out to me here:

1. The testing libraries should live in the $ANT_HOME/lib directory because of
the classloader issues that you mention. (You are running your Junit tests from
within ant right?)
2. Do you have your JAVA_HOME environment variable set? (Mine is
"/System/Library/Frameworks/JavaVM.framework/Home" if that helps).

I have no problem running Junit tests on my Mac, but I do run them from ant.

Simon

-----------------------------------------------------------------
Simon P. Chappell                     simon.chappell@...
Java Programming Specialist                      www.landsend.com
Lands' End, Inc.                                   (608) 935-4526

"Never give in - never, never, never, never, in nothing great or
small, large or petty, never give in except to convictions of
honor and good sense." - Sir Winston Churchill


>-----Original Message-----
>From: eriknorvelle [mailto:eriknorvelle@...]
>Sent: Friday, August 29, 2003 3:52 PM
>To: junit@yahoogroups.com
>Subject: [junit] Classloader troubles on Mac OS X
>
>
>Folks:
>
>I'm using OS X to run my Junit tests, and have found that am getting
>NoClassDefFoundError at runtime with regards to classes that my
>TestCases rely on.  In particular, I am trying to use HttpUnit.
>
>Here's my setup:
>* Mac OS X with the Apple JDK 1.4.1
>* httpunit.jar (and its dependent jars) in /Library/Java/Extensions
>* junit.jar in /Library/Java/Extensions
>* Everything compiles OK... i.e. Project Builder sees HttpUnit
>and Junit
>* My code in NewcalTestSuite.jar, packaged as executable jarfile
>* Ran via "java -jar NewcalTestSuite.jar", no additional classpath set
>
>Upon running the tests, my own TestCase class is found (not
>surprisingly), as are the Junit classes contained in junit.jar.
>However, no other classes are found, such as
>com.meterware.httpunit.WebConversation
>
>My preliminary guess is that the Junit reloading classloader doesn't
>know about the standard Mac OS Java classpaths, e.g.
>/Library/Java/Extensions, /System/Library/Java/Extensions, and
>~/Library/Java/Extensions
>
>Any known solutions to this issue?
>
>Please cc: any replies to me at norvelle@..., since I'm not
>setup to get all mail from this list.
>
>Thanks!
>
>
>
>------------------------ Yahoo! Groups Sponsor
>---------------------~-->
>Buy Ink Cartridges or Refill Kits for Your HP, Epson, Canon or Lexmark
>Printer at Myinks.com. Free s/h on orders $50 or more to the
>US & Canada. http://www.c1tracking.com/l.asp?cid=5511
>http://us.click.yahoo.com/l.m7sD/LIdGAA/qnsNAA/5cFolB/TM
>---------------------------------------------------------------
>------~->
>
>To unsubscribe from this group, send an email to:
>junit-unsubscribe@yahoogroups.com
>
>
>Your use of Yahoo! Groups is subject to
>http://docs.yahoo.com/info/terms/
>
>
>

#9265 From: Brian Button <bbutton01@...>
Date: Tue Sep 2, 2003 5:56 pm
Subject: Re: Class that calls on database helper class. How to write test case?
bbutton
Send Email Send Email
 
On Fri, 2003-08-29 at 20:43, Veny handoko wrote:
> Hi all,

Hi, Veny,

I know you've already had an answer, but I've got a couple of other
options that I've used in the past that might be useful as well.

>
> I am new to Junit and i am trying to write test case on class that involve
database.

Basically, you're problem comes down to the design smell of directly
instantiating another object inside your code. The act of instantiating
an object and the act of using are two different concerns, so they may
want to live in two different functions -- there are exceptions to this,
so consider it a guideline more than a rule. Actually, I usually start
by creating an object inline, then refactor to something better if I
need it. And in this case, you need it :)

So, first of all, refactor the creation into a factory method in your
class:

> public class BusinessObject{
>     public boolean methodCall(int key){
>         DatabaseHelper dbHelper = createDatabaseHelper();
>         Vector v = dbHelper.getList();
>         if(v.size() == 0){
>             return false;
>         }else{
>             return true;
>         }
>     }

	 protected DatabaseHelper createDatabaseHelper() {
		 return DatabaseHelper();
	 }
> }

Now in your test code, you can inherit from BusinessObject, and
substitute your own factory method in your derived class to create and
return whatever mock DatabaseHelper you want. This is probably the least
intrusive way to solve this problem.

Another solution is to put the onus of creating the appropriate kind of
DatabaseHelper onto the creator of the BusinessObject. They can create
either the real one (DatabaseHelper) or a mock one, and pass it into the
constructor of BusinessObject. This requires that the client knows a
little more about what they want to do, and it requires a change to the
signature of this object.

The final solution, as proposed by another poster, is to use a factory
object whose job it is to create an instance of DatabaseHelper. You
would still have to pass in an instance of this factory to the
BusinessObject class, so it could call it instead of directly creating
the object in the createDatabaseHelper() method:

	 protected DatabaseHelper createDatabaseHelper() {
		 return factory.createDatabaseHelper();
	 }

Given all the options, I'd choose the first one most of the time, only
using one of the other two if I needed something more flexible than
option 1.

HTH,
bab

--
Brian Button 	 bbutton@...
Principal Consultant  http://www.agilesolutionsgroup.com
Agile Solutions Group  636.399.3146
St. Louis, MO

Extreme Programming in St. Louis-http://www.groups.yahoo.com/group/xpstl

#9266 From: junit@yahoogroups.com
Date: Tue Sep 2, 2003 8:39 pm
Subject: New file uploaded to junit
junit@yahoogroups.com
Send Email Send Email
 
Hello,

This email message is a notification to let you know that
a file has been uploaded to the Files area of the junit
group.

   File        : /reloadtest.zip
   Uploaded by : neil_swingler <neil@...>
   Description : Classloader that reloads the TestCase class for each test
instance.

You can access this file at the URL

http://groups.yahoo.com/group/junit/files/reloadtest.zip

To learn more about file sharing for your group, please visit

http://help.yahoo.com/help/us/groups/files

Regards,

neil_swingler <neil@...>

#9267 From: Piergiuliano Bossi <P.Bossi@...>
Date: Tue Sep 2, 2003 3:37 pm
Subject: Re: Problem using JWebUnit
pgbossi
Send Email Send Email
 
The problem lies probably in HttpUnit javascript support (that is, if I
remember correctly, Rhino).
You should address your question to HttpUnit forums (take a look at
sourceforge).

Ciao, Giuliano


Anbarasan Chandramohan wrote:

> Hi All,
>
>    We are using JWebUnit for testing Web Applications. Jwebunit is
> internally using JUnit for assertions.
>    This code is for testing whether a table is present in a web page
> and clicking a link present in the table.
>
>    public class Bug9482TestScript extends WebTestCase
>    {
>    public Bug9482TestScript(String name)
>    {
>       super(name);
>    }
>    public void setUp()
>    {
>       getTestContext().setBaseUrl("http://localhost:1760/myPage");
>    }
>    public void testMessage()
>    {
>       beginAt("/");
>       setFormElement("uid", "System");
>       setFormElement("password", "Manager");
>       submit("Submit");
>       gotoRootWindow();
>       assertLinkPresentWithText("Learning Activities");
>       clickLinkWithText("Learning Activities");
>       gotoRootWindow();
>       assertTablePresent("mySummary");
>       assertTextInTable("mySummary","Blended Activity");
>       assertTextInTable("mySummary","1001");
>       //clickLinkWithText("1001");
>
>       I am able to find the link text present in the table. But if i
> try to click the link, it's throwing this Runtime Exception.
> If anybody knows the solution, please send to our group.
> Exception:
>      java.lang.RuntimeException:
> com.meterware.httpunit.ScriptException: Script '// fill the form if it
> is cacheable
> if (typeof form_cacher != 'undefined')
>     form_cacher.fillFromUrl(document.location.href);' failed:
> ConversionError: The undefined value has no properties. (httpunit;
> line 162)
> at
>
com.meterware.httpunit.javascript.JavaScript$JavaScriptEngine.handleScriptExcept\
ion(JavaScript.java:182)
> at
>
com.meterware.httpunit.javascript.JavaScript$JavaScriptEngine.executeScript(Java\
Script.java:119)
> at
>
com.meterware.httpunit.scripting.ScriptableDelegate.runScript(ScriptableDelegate\
.java:55)
> at
> com.meterware.httpunit.ScriptFilter.getTranslatedScript(ScriptFilter.java:140)
> at com.meterware.httpunit.ScriptFilter.endElement(ScriptFilter.java:121)
> at org.cyberneko.html.HTMLTagBalancer.endElement(Unknown Source)
> at org.cyberneko.html.HTMLScanner$SpecialScanner.scan(Unknown Source)
> at org.cyberneko.html.HTMLScanner.scanDocument(Unknown Source)
> at org.cyberneko.html.HTMLConfiguration.parse(Unknown Source)
> at org.cyberneko.html.HTMLConfiguration.parse(Unknown Source)
> at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
> at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
> at com.meterware.httpunit.NekoHTMLParser.parse(NekoHTMLParser.java:49)
> at com.meterware.httpunit.HTMLPage.parse(HTMLPage.java:249)
> at
> com.meterware.httpunit.WebResponse.getReceivedPage(WebResponse.java:918)
> at com.meterware.httpunit.WebResponse.access$100(WebResponse.java:49)
> at
> com.meterware.httpunit.WebResponse$Scriptable.load(WebResponse.java:572)
> at
>
com.meterware.httpunit.javascript.JavaScript$Window.initialize(JavaScript.java:3\
90)
> at com.meterware.httpunit.javascript.JavaScript.run(JavaScript.java:80)
> at
>
com.meterware.httpunit.javascript.JavaScriptEngineFactory.associate(JavaScriptEn\
gineFactory.java:46)
> at com.meterware.httpunit.FrameHolder.updateFrames(FrameHolder.java:82)
> at
> com.meterware.httpunit.WebWindow.updateFrameContents(WebWindow.java:184)
> at
> com.meterware.httpunit.WebClient.updateFrameContents(WebClient.java:472)
> at com.meterware.httpunit.WebWindow.updateWindow(WebWindow.java:167)
> at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:111)
> at com.meterware.httpunit.WebWindow.sendRequest(WebWindow.java:99)
> at
>
com.meterware.httpunit.WebRequestSource.submitRequest(WebRequestSource.java:204)
> at
>
com.meterware.httpunit.WebRequestSource.submitRequest(WebRequestSource.java:195)
> at com.meterware.httpunit.WebLink.click(WebLink.java:86)
> at net.sourceforge.jwebunit.HttpUnitDialog.submitRequest(Unknown Source)
> at net.sourceforge.jwebunit.HttpUnitDialog.clickLinkWithText(Unknown
> Source)
> at net.sourceforge.jwebunit.WebTester.clickLinkWithText(Unknown Source)
> at net.sourceforge.jwebunit.WebTestCase.clickLinkWithText(Unknown Source)
> at
>
net.sourceforge.jwebunit.sample.Bug9482TestScript.testMessage(Bug9482TestScript.\
java:32)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at
>
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav\
a:25)
>
> at net.sourceforge.jwebunit.HttpUnitDialog.submitRequest(Unknown Source)
> at net.sourceforge.jwebunit.HttpUnitDialog.clickLinkWithText(Unknown
> Source)
> at net.sourceforge.jwebunit.WebTester.clickLinkWithText(Unknown Source)
> at net.sourceforge.jwebunit.WebTestCase.clickLinkWithText(Unknown Source)
> at
>
net.sourceforge.jwebunit.sample.Bug9482TestScript.testMessage(Bug9482TestScript.\
java:32)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at
>
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav\
a:25)
>
>
> Thanks in Advance,
> A.Chandramohan
>
>
> ---------------------------------
> Do you Yahoo!?
> Yahoo! SiteBuilder - Free, easy-to-use web site design software
>
> [Non-text portions of this message have been removed]
>
>
>
> Yahoo! Groups Sponsor
> ADVERTISEMENT
>
<http://rd.yahoo.com/M=251812.3170658.4537139.1261774/D=egroupweb/S=1705006905:H\
M/A=1693352/R=0/SIG=11tralmvc/*http://www.netflix.com/Default?mqso=60178293&part\
id=3170658>
>
>
>
> To unsubscribe from this group, send an email to:
> junit-unsubscribe@yahoogroups.com
>
>
> Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service
> <http://docs.yahoo.com/info/terms/>.



[Non-text portions of this message have been removed]

#9268 From: "yau20021025" <yau20021025@...>
Date: Tue Sep 2, 2003 9:17 pm
Subject: Please Help!!~
yau20021025
Send Email Send Email
 
Hello,
I am a student, currently doing an industrial experience project for
my degree. JUnit is totally new for me. My client requested me to
update the JUnit in the system to version 3.8.1.

c:/work/xp/lib/ is the directory which stores the junit.jar.
I replace the junit.jar with the newest version of junit.jar I just
downloaded recently and
build clean refreshdb deploy are all successful. Only build test is
giving me problem. It seems like all test files cannot be tested at
all. All tests are failed.
[Junitreport] stated that *alltestfile*.xml is not a valid XML
document, it is possibly corrupted.

My client told me that JUnit has changed significantly.
Do I need to modify anything in build.xml?
Is it only replacing the newest junit.jar but no others?
Where can I find a site that shows me the way to update JUnit from
older version to newest version3.8.1? (I am not sure which version I
am currently using but I think it is only a bit older that
3.8.1,Sorry!)

May be I have missed out something in converting the version. I am
not sure. Can anyone out there please teach me about this issue.
Your advises and answers are really appreciated.

Thank you so much!

Best Regards,
wenyew

#9269 From: "J. B. Rainsberger" <jbrains@...>
Date: Wed Sep 3, 2003 1:51 am
Subject: Re: Please Help!!~
nails762
Send Email Send Email
 
yau20021025 wrote:

> Hello,
> I am a student, currently doing an industrial experience project for
> my degree. JUnit is totally new for me. My client requested me to
> update the JUnit in the system to version 3.8.1.
<snip />

I can't imagine why you would encounter such a problem. I recommend
putting back an older version of JUnit to see whether, by chance, you
changed (or someone else changed) something else at the same time as
changing JUnit. The problems you describe are not likely to be caused
just by upgrading JUnit.
--
J. B. Rainsberger,
Diaspar Software Services
http://www.diasparsoftware.com :: +1 416 791-8603
Let's write software that people understand

#9270 From: "Day, Jem BGI SF" <jem.day@...>
Date: Wed Sep 3, 2003 6:55 pm
Subject: RE: Class that calls on database helper class. How to wri te test case?
vladti
Send Email Send Email
 
You may also want to consider taking a look at dbunit (JUnit extension) to
ease DB Testing

http://www.dbunit.org



-----Original Message-----
From: Veny handoko [mailto:vichandoko@...]
Sent: Friday, August 29, 2003 6:43 PM
To: junit@yahoogroups.com
Subject: [junit] Class that calls on database helper class. How to write
test case?


Hi all,

I am new to Junit and i am trying to write test case on class that involve
database.

Here is snapshot of my design.

public class BusinessObject{
     public boolean methodCall(int key){
         DatabaseHelper dbHelper = new DatabaseHelper();
         Vector v = dbHelper.getList();
         if(v.size() == 0){
             return false;
         }else{
             return true;
         }
     }
}

public class DatabaseHelper{
     Connection con;
     ...

     public Vector getList(){
         Vector v = new Vector();
         //perform query to database to retrieve a list of values and add
into Vector
         return v;
     }
}

How to write a test case for the method inside BusinessObject? For instance,
if i want to test BusinessObject.methodCall on condition where getList()
return an empty list, how should it be done? I am not expected to empty my
database to do this, right? Is the any way to mock my DatabaseHelper object?
How to do it?

I've look at MockObject. but the sample given on mockObject website
requires me to pass in a Connection to DatabaseHelper, which i personally
think it not quite a good design considering modularity. Any other
alternatives?

I believe this is quite common problem/question. Can somebody send me a
sample test case if available. Thank you very much.

Cheers,

Veny



---------------------------------
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software

[Non-text portions of this message have been removed]




To unsubscribe from this group, send an email to:
junit-unsubscribe@yahoogroups.com


Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/

#9271 From: Brian Button <bbutton01@...>
Date: Wed Sep 3, 2003 7:09 pm
Subject: RE: Class that calls on database helper class. How to wri te test case?
bbutton
Send Email Send Email
 
On Wed, 2003-09-03 at 13:55, Day, Jem BGI SF wrote:
> You may also want to consider taking a look at dbunit (JUnit extension) to
> ease DB Testing
>
> http://www.dbunit.org

While I appreciate the answer, I also believe that using it would be a
mistake in this case. His problem is that his Business Object is
directly tied to his persistence store. This is a tight coupling that
needs to be broken, IMO.

bab

--
Brian Button 	 bbutton@...
Principal Consultant  http://www.agilesolutionsgroup.com
Agile Solutions Group  636.399.3146
St. Louis, MO

Extreme Programming in St. Louis-http://www.groups.yahoo.com/group/xpstl

#9272 From: "J. B. Rainsberger" <jbrains@...>
Date: Thu Sep 4, 2003 2:01 am
Subject: Re: Class that calls on database helper class. How to wri te test case?
nails762
Send Email Send Email
 
Brian Button wrote:

> On Wed, 2003-09-03 at 13:55, Day, Jem BGI SF wrote:
>  > You may also want to consider taking a look at dbunit (JUnit
> extension) to
>  > ease DB Testing
>  >
>  > http://www.dbunit.org
>
> While I appreciate the answer, I also believe that using it would be a
> mistake in this case. His problem is that his Business Object is
> directly tied to his persistence store. This is a tight coupling that
> needs to be broken, IMO.

Agreed. DBUnit is a great tool for priming the database with data, but
that is for end-to-end or Integration Tests, and not Object Tests.

If the original questioner wants to write Object Tests for his JDBC
client code, he should *at a minimum* decouple his Business Objects from
a JDBC Connection/DataSource/whatever.

I'm saying more on the topic, but that won't be in bookstores until
about February.
--
J. B. Rainsberger,
Diaspar Software Services
http://www.diasparsoftware.com :: +1 416 791-8603
Let's write software that people understand

#9273 From: "cpac_22" <cpac_22@...>
Date: Thu Sep 4, 2003 4:54 am
Subject: Code to right-click
cpac_22
Send Email Send Email
 
I'm new to JUnit/JFCUnit, and I was wondering if anyone could give me
some code on how to perform/simulate a right-click  from the mouse. I
can do a normal left-click:

helper.enterClickAndLeave(new MouseEventData(aTestCase, anObject));

but how to right-click on this object, is difficult.

#9274 From: Venkatesh Prasad Ranganath <java-junit@...>
Date: Thu Sep 4, 2003 6:24 pm
Subject: Domain specific question
java-junit@...
Send Email Send Email
 
Hi,

I have read about JUnit and TDD and the mailing list about using these in real
world.  However I am still not convinced how
would one apply these in large systems.  In particular, in compilers and related
topics.

A concrete instance would be an analysis that works on say some IR. The analysis
can usually be cast as a single class and the
test of the "unit" is that each of the methods function as specified in the
given scenarios.  The analysis works on the
intermediate representation (IR) of a program.  The IR is dependent on the input
program/source code.

To test the analysis class you need to provide it an IR which means we need the
whole machinery to setup the IR on which the
analysis works and then drive the analysis with the test object while probing it
correctness.  Generally, the machinery to
setup the IR is complex or large.  So, would one code that up into the test
case?  If so, at what cost?  A more simple
question would be that how much effort should go into setting up the environment
for object to be tested and test object
itself?  Also, say if the analysis provides information say relation between 2
entities in the IR, then how do you test for
this relation while unit testing the analysis (may be this is into another form
of testing but anyways...)?

For people who have read "Unit Testing in Java" the above is a case of Object
Under Test scenario.

In simple words, if a chunk of logic embedded in a class requires large pieces
of information to be setup, then how would one
use JUnit or any unit testing framework in such cases?  Even more, when
instances of such classes go through state changes
depending on interaction with other objects how do you instrument the test and
run the test?

The reason I am posting this question is that I have heard a lot about JUnit and
how Unit Testing is the "magic bullet" (of
course I have heard people say otherwise about the latter too).  However, I am
not convinced as to if it is applicable in all
situations and scenarios.  Even more, are there documents or studies that
indicate the impact of Unit Testing on projects say
in terms of shift in timelines, # of bugs, and such?  I am trying to find
evidence of usage of JUnit is situations similar to
ones explained above.

waiting for reply,

- Venkatesh

#9275 From: "J. B. Rainsberger" <jbrains@...>
Date: Thu Sep 4, 2003 9:30 pm
Subject: Re: Domain specific question
nails762
Send Email Send Email
 
Venkatesh Prasad Ranganath wrote:

> Hi,
>
> I have read about JUnit and TDD and the mailing list about using these
> in real world.  However I am still not convinced how
> would one apply these in large systems.  In particular, in compilers and
> related topics.

How to apply them to large systems is something that's well-worn by this
point. Large systems are just larger collections of objects, so not much
is different.

As for compilers, your message seems to claim that building a compiler
incrementally is not possible, or perhaps just not feasible. The way to
build a compiler incrementally -- assuming you do not use any existing
tools like parser generators -- is to pick one language feature and
support it, then another, then another until you support the entire
language.

Another approach is to start by implementing an interpreter, work to
support the entire language, then use the interpreter as a test
environment to write the corresponding compiler. That's just an idea
that comes off the top of my head and I have no idea whether it's feasible.

Your question, it seems to me, is about incremental development and not
TDD and not JUnit. Is that accurate? I only mention that because it's
easier to answer a question once I understand the question.
--
J. B. Rainsberger,
Diaspar Software Services
http://www.diasparsoftware.com :: +1 416 791-8603
Let's write software that people understand

#9276 From: Venkatesh Prasad Ranganath <java-junit@...>
Date: Thu Sep 4, 2003 9:57 pm
Subject: Re: Domain specific question
java-junit@...
Send Email Send Email
 
J. B. Rainsberger wrote:
> Venkatesh Prasad Ranganath wrote:
>
>
>>Hi,
>>
>>I have read about JUnit and TDD and the mailing list about using these
>>in real world.  However I am still not convinced how
>>would one apply these in large systems.  In particular, in compilers and
>>related topics.
>
>
> How to apply them to large systems is something that's well-worn by this
> point. Large systems are just larger collections of objects, so not much
> is different.
>
> As for compilers, your message seems to claim that building a compiler
> incrementally is not possible, or perhaps just not feasible. The way to
> build a compiler incrementally -- assuming you do not use any existing
> tools like parser generators -- is to pick one language feature and
> support it, then another, then another until you support the entire
> language.
>
> Another approach is to start by implementing an interpreter, work to
> support the entire language, then use the interpreter as a test
> environment to write the corresponding compiler. That's just an idea
> that comes off the top of my head and I have no idea whether it's feasible.
>
> Your question, it seems to me, is about incremental development and not
> TDD and not JUnit. Is that accurate? I only mention that because it's
> easier to answer a question once I understand the question.

No, the question is when you have many phases that setup the data on which an
analysis works, how do you unit test the
analysis efficiently?  It may take a long time to setup the data, hence, the
code-test-refactor cycle will prove rather costly.

To make things simple, consider a report generation application which adds some
interesting facts to the report based on the
data being reported.  Now the nature of the report per say is dictated by the
data, however, the data being generated may
depend on relation between various pieces of the data.  In the example, the
report generator has a strong coupling with the
data generator but this is purely restricted to input data and no more (I am
just clearing things in case people start saying
"reduce the coupling").  Now the information about input data (call it
meta-data) which is also of relevance to report
generator and this is not captured as a programmable software entity. How does
one use TDD and/or JUnit in such cases is my
question?

All examples of JUnit or TDD I have seen are Money and things on those lines
which are stand alone classes.  However, things
change radically when you move to frameworks.  Referring to my first posting, in
my opinion, a compiler is more of a framework
rather than a single large application.  It is put together from peices and not
grown from a single blob.  The Type checker is
dependent on the AST and the AST is dependent on the Parser Tree which is
dependent on parsing and the Parser.  Given this
chain, how do you unit test each link in the chain?

I hope I am making sense.  If not then may be someone can present a plausible
solution to the above problem or something
similar?  I would really appreciate it as I want to use TDD and JUnit, but
somehow I cannot see a way to make it fit into my
work/application model.

waiting for reply,

   - Venkatesh

#9277 From: "Selvakumar Ganesan" <selvakumar.ganesan@...>
Date: Fri Sep 5, 2003 4:08 am
Subject: RE: Domain specific question
webaesthet
Send Email Send Email
 
It is an interesting question:
" So, would one code that up into the test case?  If so, at what cost?  A more
simple question would be that how much effort should go into setting up the
environment for object to be tested and test object
itself?"

We had a similar experience in a project recently. The team found JUnit (tests
at class level)to be too restrictive. So, it ended up creating a test framework
extended from JUnit and mocking all external components. This extended framework
tested all the interfaces and also simulated the - quite complex -
multi-threaded runtime environment. Developers were then on their own to write
Unit tests for classes using the extended test framework. The effort investment
is quite large for building such complex test frameworks.
The final word must come from answering "what makes sense?" (and, of course,
from the client's pockets).

I agree with your reasonable scepticism. JUnit is not The Hammer and not
everything is a nail.

regards,
Selva.


    Date: Thu, 04 Sep 2003 13:24:27 -0500
    From: Venkatesh Prasad Ranganath <java-junit@...>
Subject: Domain specific question

Hi,

I have read about JUnit and TDD and the mailing list about using these in real
world.  However I am still not convinced how
would one apply these in large systems.  In particular, in compilers and related
topics.

A concrete instance would be an analysis that works on say some IR. The analysis
can usually be cast as a single class and the
test of the "unit" is that each of the methods function as specified in the
given scenarios.  The analysis works on the
intermediate representation (IR) of a program.  The IR is dependent on the input
program/source code.

To test the analysis class you need to provide it an IR which means we need the
whole machinery to setup the IR on which the
analysis works and then drive the analysis with the test object while probing it
correctness.  Generally, the machinery to
setup the IR is complex or large.  So, would one code that up into the test
case?  If so, at what cost?  A more simple
question would be that how much effort should go into setting up the environment
for object to be tested and test object
itself?  Also, say if the analysis provides information say relation between 2
entities in the IR, then how do you test for
this relation while unit testing the analysis (may be this is into another form
of testing but anyways...)?

For people who have read "Unit Testing in Java" the above is a case of Object
Under Test scenario.

In simple words, if a chunk of logic embedded in a class requires large pieces
of information to be setup, then how would one
use JUnit or any unit testing framework in such cases?  Even more, when
instances of such classes go through state changes
depending on interaction with other objects how do you instrument the test and
run the test?

The reason I am posting this question is that I have heard a lot about JUnit and
how Unit Testing is the "magic bullet" (of
course I have heard people say otherwise about the latter too).  However, I am
not convinced as to if it is applicable in all
situations and scenarios.  Even more, are there documents or studies that
indicate the impact of Unit Testing on projects say
in terms of shift in timelines, # of bugs, and such?  I am trying to find
evidence of usage of JUnit is situations similar to
ones explained above.

waiting for reply,

- Venkatesh




[Non-text portions of this message have been removed]

#9278 From: Ives Aerts <ives+junit@...>
Date: Fri Sep 5, 2003 12:24 pm
Subject: Reloading tests with text runner?
ivesaerts
Send Email Send Email
 
We are using JUnit on an embedded platform where:
   + restarting the VM is expensive
   + we can only use the junit.textui.TestRunner
   + we can update jar files on the platform and restart tests by
     attaching to the (running VM) and calling TestRunner.run()

Is it possible to make the textui TestRunner use a new classloader for
each invocation so that tests and tested classes are reloaded from the
updated jar files?

Cheers,
-Ives
______________________________________________________________________
Ives Aerts                      Sony Visual Products Europe - Brussels
Ives.Aerts@...                    http://www.vpe-b.sonycom.com
`Strange women lying in ponds distributing swords is no basis for
  a system of government.'              (Monty Python - The Holy Grail)

#9279 From: "J. B. Rainsberger" <jbrains@...>
Date: Fri Sep 5, 2003 12:38 pm
Subject: Re: Re: Domain specific question
nails762
Send Email Send Email
 
Venkatesh Prasad Ranganath wrote:

> J. B. Rainsberger wrote:
>  > Venkatesh Prasad Ranganath wrote:
>  >
>  >
>  >>Hi,
>  >>
>  >>I have read about JUnit and TDD and the mailing list about using these
>  >>in real world.  However I am still not convinced how
>  >>would one apply these in large systems.  In particular, in compilers and
>  >>related topics.
>  >
>  >
>  > How to apply them to large systems is something that's well-worn by this
>  > point. Large systems are just larger collections of objects, so not much
>  > is different.
>  >
>  > As for compilers, your message seems to claim that building a compiler
>  > incrementally is not possible, or perhaps just not feasible. The way to
>  > build a compiler incrementally -- assuming you do not use any existing
>  > tools like parser generators -- is to pick one language feature and
>  > support it, then another, then another until you support the entire
>  > language.
>  >
>  > Another approach is to start by implementing an interpreter, work to
>  > support the entire language, then use the interpreter as a test
>  > environment to write the corresponding compiler. That's just an idea
>  > that comes off the top of my head and I have no idea whether it's
> feasible.
>  >
>  > Your question, it seems to me, is about incremental development and not
>  > TDD and not JUnit. Is that accurate? I only mention that because it's
>  > easier to answer a question once I understand the question.
>
> No, the question is when you have many phases that setup the data on
> which an analysis works, how do you unit test the
> analysis efficiently?  It may take a long time to setup the data, hence,
> the code-test-refactor cycle will prove rather costly.
>
> To make things simple, consider a report generation application which
> adds some interesting facts to the report based on the
> data being reported.  Now the nature of the report per say is dictated
> by the data, however, the data being generated may
> depend on relation between various pieces of the data.  In the example,
> the report generator has a strong coupling with the
> data generator but this is purely restricted to input data and no more
> (I am just clearing things in case people start saying
> "reduce the coupling").  Now the information about input data (call it
> meta-data) which is also of relevance to report
> generator and this is not captured as a programmable software entity.
> How does one use TDD and/or JUnit in such cases is my
> question?
>
> All examples of JUnit or TDD I have seen are Money and things on those
> lines which are stand alone classes.  However, things
> change radically when you move to frameworks.  Referring to my first
> posting, in my opinion, a compiler is more of a framework
> rather than a single large application.  It is put together from peices
> and not grown from a single blob.  The Type checker is
> dependent on the AST and the AST is dependent on the Parser Tree which
> is dependent on parsing and the Parser.  Given this
> chain, how do you unit test each link in the chain?

You test each link in isolation by verifying the contracts of each
interface, then subtituting simpler collaborators as needed in tests.

My experience is in J2EE, so I can best describe it there. The short
version follows. The long version will be published this winter and in
bookstores early next year.

My web application consists of a controller (Servlet), presentation
layer (JavaBeans and Velocity templates), business layer (POJOs) and
data access layer (JDBC). It has several key behaviors:

   * control navigation from one page to another
   * select business logic based on a request
   * update data based on business logic
   * display data on a web page

There are others. Each behavior, like your compiler example, is
implemented by collaborations of objects, which gives you pause. Well,
how do I test the navigation rules? Simple, really: for each
action/outcome pair, decide which page should come next and with which
data. Now simulate that action/outcome pair as simply as you can, then
invoke the Navigator (usually part of the controller) and verify the
next page the Navigator chooses.

Usually this is as simple as sending a URL (the action) and a single
value (the outcome) with perhaps some data (an object, such as a Map) to
a Navigator object invoking a method called "getForwardUri()", which
answers a URI (a String). The controller can use this information to
forward the request to that URI.

I can verify that the controller actually does forward to a URI I give
it with a single ServletUnit test.

Notice that we are not performing the action. We are simulating the
action and forcing it to a specific outcome for the purposes of
answering the question, "Where does the Navigator want to go if I tell
it that Action XXX ends with outcome YYY?" For testing the Navigator,
that's all we need to do.

Once you apply this technique everywhere, all that is left -- and it's
still a fair amount of work -- is to verify that the Application
configures the pieces correctly. A run of end-to-end tests shows that we
have put correctly-working pieces together correctly.

Now let me see whether I can apply this to your domain.

  > The Type checker is
  > dependent on the AST and the AST is dependent on the Parser Tree which
  > is dependent on parsing and the Parser.

OK. I assume that the Parser turns source code into a ParserTree, then
the ParserTree transforms itself into an AbstractSyntaxTree, then the
TypeChecker analyzes the AbstractSyntaxTree and generators errors if
any. Even if that's not entirely correct, it's close enough for this
discussion. Feel free to correct me, but read what I write below anyway,
because I think it'll help.

So to test the Parser, give it bits of source code. Not big bits; small
bits. A few statements. Single constructs. Since its output is a Tree,
as long as the Parser spits out the expected Tree for each atomic
construct *and* can put those AtomicConstructTree objects in the right
place in a big ParserTree (for big source code), you're done. The
recursive nature of tree structures makes this particularly easy to
reduce to smaller problems. In other words, verify that the Parser
orders constructs correctly in a Tree *and* knows how to translate each
kind of construct. I don't know how many tests that is, but my guess is
roughly 3 tests per construct plus perhaps 5 tests for the tree. 3n+5,
then, for n different kinds of constructs.

When I read "All the TDD examples are so simple," I think of arithmetic.

There is no such thing as a complex arithmetic question (+, -, *, /). I
am amazed when a young person -- say 15 years old -- is impressed when I
add a couple of five-digit numbers in my head. (Wow! That's hard!) But
there is no such things as a "hard" arithmetic question; only a long
one. Every arithmetic question reduces to single-digit addition. The
only question is, "How many single-digit addition operations do I need
to do?" Sometimes the answer is in the thousands. That may make it
time-consuming, but it isn't complex.

The good news is that as we practise single-digit addition, and then
single-digit multiplication, and so on... we come to do it very quickly,
so then adding a column for four-digit numbers is no longer so
time-consuming.

So I'll say this: there are no complex TDD problems; only long ones.

> I hope I am making sense.  If not then may be someone can present a
> plausible solution to the above problem or something
> similar?  I would really appreciate it as I want to use TDD and JUnit,
> but somehow I cannot see a way to make it fit into my
> work/application model.

One piece at a time. The tricky part is decoupling the application, and
that takes practise.
--
J. B. Rainsberger,
Diaspar Software Services
http://www.diasparsoftware.com :: +1 416 791-8603
Let's write software that people understand

Messages 9250 - 9279 of 24384   Oldest  |  < Older  |  Newer >  |  Newest
Add to My Yahoo!      XML What's This?

Copyright © 2010 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines NEW - Help