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...
Hear how Yahoo! Groups has changed the lives of others. Take me there.

Messages

Advanced
Messages Help
Messages 1045 - 1074 of 24393   Oldest  |  < Older  |  Newer >  |  Newest
Messages: Show Message Summaries Sort by Date ^  
#1045 From: carlos.manzanares@...
Date: Wed Apr 25, 2001 8:58 am
Subject: RE: Is coverage important? RE: Test Coverage Analysis To ol For Junit
carlos.manzanares@...
Send Email Send Email
 
Hi,

sorry for the misunderstanding: I have found that a very common policy in QA
is to have a fixed coverage percentage (usually 80%) and, in that basis, I
understood wrong your e-mail.
I completly agree with your explanation... I apologize for my wrong
interpretation of your ideas.

--Carlos--

> -----Original Message-----
> From: ext Steve Freeman [mailto:steve@...]
> Sent: 25 April, 2001 11:01
> To: junit@yahoogroups.com
> Subject: Re: [junit] Is coverage important? RE: Test Coverage Analysis
> To ol For Junit
>
>
> From: <carlos.manzanares@...>
> > I think what we are all afraid is of Steve's statement: "If
> you're really
> > writing code test-first you should find that you hit 98-99%
> coverage without
> > breaking into a sweat." I have never liked imposed coverage
> percentages
> > because not all the applications can be covered in the same
> way (some
> > applications are very easy to be covered and some others
> are impossible),
> > and because usually the developers start to trick with the
> tests just to get
> > that percentages (and usually that tricks are not very
> "quality-oriented"
> > and at the end they are a waste of time)
>
> I think we've misunderstood something here. I was not
> proposing full coverage as a requirement or anything like
> that. My point was that one of the effects of writing code
> test-first (where you shouldn't write code without a test to
> drive it) is that you get full coverage "for free". Just run
> the tool from time to time to look for occasional slip-ups
> and stop worrying about it.
> We all know that coverage, in itself, does not prove that
> you've executed every possible path, just as unit tests do
> not _prove_ that your code has no errors, but it gets you a
> lot of the way there.
>
> Steve
>
>
> 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/
>
>

#1046 From: Joshua Levy <joshualevy@...>
Date: Wed Apr 25, 2001 4:29 pm
Subject: Re: Is coverage important? RE: Test Coverage Analysis To ol For Junit
joshualevy@...
Send Email Send Email
 
One of my mottos is this:
    "If it's not tested, it doesn't work"
(Which I came up with for Veritas's ViSTA group.)
An obvious related rule is this:
    "If you don't have coverage numbers, you
     don't know if it works."

So, to me, there is no question that coverage
is important.  But I don't believe that 100%
coverage is important.  My experience has been
that you get about 30% coverage by doing almost
any testing at all.  That is almost a freebee.
Going from 30% to 60% coverage is a huge win
in terms of finding bugs, and is absolutely the
second kind of testing you should do.  Getting
coverage numbers up from 60% to 80%-90% is
valuable too, but you need to juggle this value
against other valuable forms of testing.
(Load testing, for example.)  So you may want
to do load testing after your coverage numbers
are at 60%, but before you push them to 80%.
Moving above 80%-90% coverage takes a lot of
work, and may not be cost effective.

I think going from 30% to 60% testing coverage
is the second kind of testing you should do.
The first kind is what I call "user first
experience testing".  You can't really do this
with junit (unfortunately).  Basically this is
taking someone who has never used the product
before, and watching them find/install/learn/use
the product for the first time.  That is the
most valuable form of testing, because it is
absolutely the first thing all customers will
do with you product.

Joshua Levy

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

#1047 From: mhowk@...
Date: Wed Apr 25, 2001 4:51 pm
Subject: TestSetup and the Test Hierarchy
mhowk@...
Send Email Send Email
 
Is there any way to use the TestSetup decorator AND see each test in
the Test Hierarchy window in the swing UI? I've seen this question
several times (and asked it once), but I haven't seen any
conclusions. Has anyone done this, or is it impossible with the
current version of JUnit?

#1048 From: "Joe Fisher" <jfisher@...>
Date: Wed Apr 25, 2001 5:02 pm
Subject: setup dynamic data
jfisher@...
Send Email Send Email
 
I have played with junit and also written crude testing frameworks.
I am currently working with a project that interfaces with PVCS Version
Manager.
When I run my test, I try to checkout/check in files, but whenever I run my
test suite
I need to delete all the subfolders and copy them from a backup so I can be
in a known state
I also have to have the user check in version manager if the file actually
got checkedin/checkout

My question is:
In these dynamic situations (testing databases data/ etc) What is the best
way to handle
setup and teardown such that my test will be consistent.
Also, how would I automatically decide that the file has been
checkedin/checkedout.
Thanks in advance.

Joe Fisher, Software Developer
Xtend Inc.
http://www.xtendsoft.com
voice  801.825.5553 ext 309
fax    801.825.5606
e-mail jfisher@...
s-mail 1645 East Hwy 193, Suite 202
        Layton, Ut 84041

#1049 From: "Charles Medcoff" <cmedcoff@...>
Date: Thu Apr 26, 2001 12:09 am
Subject: How to get a stack trace with junit.textui.TestRunner
cmedcoff@...
Send Email Send Email
 
I have found that if I write a main() for a TestCase that any asserts
that fail give a stack trace.  For example

class MyTest extends TestCase //...
//...

   public static void main(String args[])
   {
     MyTest my = new MyTest(//...
     my.setUp();
     my.testX(); // etc.
   }

However if my main looks like this

   junit.textui.TestRunner.run(suite());

I get no stack trace.  The trace is useful to get the linenumber in
the source file.  Any suggestions?  (I'm currently digging through
the docs, but please save me some time if you can.)

Regards,
Chuck

#1050 From: Jim Cheesman <jchees@...>
Date: Thu Apr 26, 2001 7:10 am
Subject: Re: setup dynamic data
jchees@...
Send Email Send Email
 
At 07:02 PM 4/25/2001, you wrote:
>I have played with junit and also written crude testing frameworks.
>I am currently working with a project that interfaces with PVCS Version
>Manager.
>When I run my test, I try to checkout/check in files, but whenever I run my
>test suite
>I need to delete all the subfolders and copy them from a backup so I can be
>in a known state
>I also have to have the user check in version manager if the file actually
>got checkedin/checkout

You could use ant (http://jakarta.apache.org) to do the check in/out
procedure - one of its built-in tasks is Cvs. As for setting up the data,
simple tasks like copying test data to/from directories, cleaning
directories etc. is also easy to setup. (I haven't used the cvs task - we
have Source Safe here, but I don't suppose that it's too difficult to set up.)

If you're using a database, as you almost certainly are, things get more
complicated ;) Some possible options:
* Someone here (I forget who) posted a "MockResultSet" class that can be
used to fake database results - I think it's available on the Yahoo groups
web page somewhere.
* You could set up a script (also executed by ant?) that creates some fake
tables in your database and populates them with data, which you could then
test against. (You have got a test database, right?) Once the tests have
been run, you could then execute a seperate script to clean up.

If anyone has any other suggestions I'd love to hear them - this is a
problem that I've come up against more than once...

(If you decide to use ant, and are not sure how to use it, feel free to
mail me).

HTH,
Jim


--

                            *   Jim Cheesman   *
              Trabajo:
jchees@... - (34)(91) 724 9200 x 2360
                Personal:
mogrim@... (34) 606 770 244
            I have a twin brother; he's
identical, but I'm not.

#1051 From: Stefan Bodewig <bodewig@...>
Date: Thu Apr 26, 2001 7:11 am
Subject: Re: setup dynamic data
bodewig@...
Send Email Send Email
 
Jim Cheesman <jchees@...> wrote:

> * You could set up a script (also executed by ant?)

Using Ant's built-in <sql> task might be even better than invoking
external scripts.

Stefan

#1052 From: Jim Cheesman <jchees@...>
Date: Thu Apr 26, 2001 7:34 am
Subject: Re: setup dynamic data
jchees@...
Send Email Send Email
 
At 09:11 AM 4/26/2001, you wrote:
>Jim Cheesman <jchees@...> wrote:
>
> > * You could set up a script (also executed by ant?)
>
>Using Ant's built-in <sql> task might be even better than invoking
>external scripts.

Learn something everyday ;) I hadn't thought of that!



--

                            *   Jim Cheesman   *
              Trabajo:
jchees@... - (34)(91) 724 9200 x 2360
                Personal:
mogrim@... (34) 606 770 244
            I have a twin brother; he's
identical, but I'm not.

#1053 From: markus_kohler@...
Date: Thu Apr 26, 2001 1:28 pm
Subject: Re: Native Code and JUnit
markus_kohler@...
Send Email Send Email
 
--- In junit@y..., marc.pages@m... wrote:
> I received help from Rama for the same problem some time ago: see
> below. With "noloading" you have to restart JUnit each time after
> modifying code.
> /Marc
>
> From:  G Ramasubramani <grama@a...>
> Date:  Mon Jan 29, 2001  2:09 pm
> Subject:  Re: [junit] Re: Native Library already loaded in another
> classloader
>
>
> This seems to be the same old issue with ClassLoaders. Try this.
> In the directory indicated by the user.home property, create a file
> called junit.properties which has the following
>
> loading=false
>
> This should solve your problem.
>
[snip]

Ok. Is this the same as toggling the new flag in the Junit 3.6 Swing
GUI?

I know that setup is called everytime. I wanted to use a static class
variable to find out that the class was already loaded.
That didn't work (of course).

I wonder how Erich Gamma himself solved this problem ...

Regards,
Markus

#1054 From: msonnet@...
Date: Thu Apr 26, 2001 2:51 pm
Subject: Java unit tests development time effort
msonnet@...
Send Email Send Email
 
Hello Everybody,

I would like to unit test a number of already developed java classes and
was wondering if you have any tips and hints to help estimate time effort
to develop those unit tests ?

We already have a build and test infrastructure based on ant 1.3 and jUnit
3.4.

Thanks a lot for your help,

Marc

#1055 From: jphedley@...
Date: Thu Apr 26, 2001 5:37 pm
Subject: J2EE Problems
jphedley@...
Send Email Send Email
 
I have experiencing the following Error when attempting to run TestSampleServlet
using J2EE version 2.2.  I am using tomcat 3.2.1 as my servlet engine.

D:\tools\jakarta-tomcat-3.2.1\webapps\expj2ee\WEB-INF\classes>java -classpath D:
\tools\jakarta-tomcat-3.2.1\lib\servlet.jar;d:\junit\junit3.4;d:\junit\j2eeunit2
.2\j2eeunit-22-0_9.jar;D:\tools\jakarta-tomcat-3.2.1\webapps\expj2ee\WEB-INF\cla
sses;d:\tools\jakarta-tomcat-3.2.1\webapps\expj2ee\test  j2eeunit.sample.TestSam
pleServlet
............E
Time: 5.984

FAILURES!!!
Test Results:
Run: 12 Failures: 0 Errors: 1
There was 1 error:
1) testRequestDispatcher(j2eeunit.sample.TestSampleServlet)
java.io.FileNotFoundException: http://localhost:8080/expj2ee/ServletRedirector
         at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown So
urce)
         at j2eeunit.client.ServletHttpClient.doTest(ServletHttpClient.java:67)
         at j2eeunit.ServletTestCase.runGenericTest(ServletTestCase.java:296)
         at j2eeunit.ServletTestCase.runTest(ServletTestCase.java:271)
         at j2eeunit.ServletTestCase.runBare(ServletTestCase.java:261)
         at junit.framework.TestResult$1.protect(TestResult.java:100)
         at junit.framework.TestResult.runProtected(TestResult.java:118)
         at junit.framework.TestResult.run(TestResult.java:103)
         at junit.framework.TestCase.run(TestCase.java:121)
         at junit.framework.TestSuite.runTest(TestSuite.java:149)
         at junit.framework.TestSuite.run(TestSuite.java:144)
         at junit.textui.TestRunner.doRun(TestRunner.java:63)
         at junit.textui.TestRunner.start(TestRunner.java:217)
         at junit.textui.TestRunner.main(TestRunner.java:89)
         at j2eeunit.sample.TestSampleServlet.main(TestSampleServlet.java:57)


When I run ServletRedirector from a browser using its URI I get the following
exception which seems reasonable from looking at the source code,

Error: 500
Location: /expj2ee/ServletRedirector
Internal Servlet Error:

javax.servlet.ServletException: Missing parameter
[ServletTestRedirector_Service] in HTTP request.
     at
j2eeunit.server.ServletTestRedirector.doPost(ServletTestRedirector.java:67)
     at
j2eeunit.server.ServletTestRedirector.doGet(ServletTestRedirector.java:50)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
     at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
     at org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
     at org.apache.tomcat.core.Handler.service(Handler.java:286)
     at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
     at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
     at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
     at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConne\
ctionHandler.java:210)
     at org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
     at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
     at java.lang.Thread.run(Thread.java:484)


So I don't believe this exception is related to what I am experiencing.  I can
run other Servlets without any problem directly or via their URI defined in the
web.xml.

Does anyone know what the problem may be?

thanks,
J.P.
__________________________________________________________________
Get your own FREE, personal Netscape Webmail account today at
http://webmail.netscape.com/

#1056 From: jphedley@...
Date: Thu Apr 26, 2001 9:23 pm
Subject: Re: J2EE Problems. Never Mind!
jphedley@...
Send Email Send Email
 
Found the problem.  Sorry for the spam.


junit@yahoogroups.com wrote:
>
> I have experiencing the following Error when attempting to run
TestSampleServlet using J2EE version 2.2.  I am using tomcat 3.2.1 as my servlet
engine.
>
> D:\tools\jakarta-tomcat-3.2.1\webapps\expj2ee\WEB-INF\classes>java -classpath
D:
>
\tools\jakarta-tomcat-3.2.1\lib\servlet.jar;d:\junit\junit3.4;d:\junit\j2eeunit2
>
.2\j2eeunit-22-0_9.jar;D:\tools\jakarta-tomcat-3.2.1\webapps\expj2ee\WEB-INF\cla
> sses;d:\tools\jakarta-tomcat-3.2.1\webapps\expj2ee\test
 j2eeunit.sample.TestSam
> pleServlet
> ............E
> Time: 5.984
>
> FAILURES!!!
> Test Results:
> Run: 12 Failures: 0 Errors: 1
> There was 1 error:
> 1) testRequestDispatcher(j2eeunit.sample.TestSampleServlet)
> java.io.FileNotFoundException: http://localhost:8080/expj2ee/ServletRedirector
>         at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown
So
> urce)
>         at j2eeunit.client.ServletHttpClient.doTest(ServletHttpClient.java:67)
>         at j2eeunit.ServletTestCase.runGenericTest(ServletTestCase.java:296)
>         at j2eeunit.ServletTestCase.runTest(ServletTestCase.java:271)
>         at j2eeunit.ServletTestCase.runBare(ServletTestCase.java:261)
>         at junit.framework.TestResult$1.protect(TestResult.java:100)
>         at junit.framework.TestResult.runProtected(TestResult.java:118)
>         at junit.framework.TestResult.run(TestResult.java:103)
>         at junit.framework.TestCase.run(TestCase.java:121)
>         at junit.framework.TestSuite.runTest(TestSuite.java:149)
>         at junit.framework.TestSuite.run(TestSuite.java:144)
>         at junit.textui.TestRunner.doRun(TestRunner.java:63)
>         at junit.textui.TestRunner.start(TestRunner.java:217)
>         at junit.textui.TestRunner.main(TestRunner.java:89)
>         at j2eeunit.sample.TestSampleServlet.main(TestSampleServlet.java:57)
>
>
> When I run ServletRedirector from a browser using its URI I get the following
exception which seems reasonable from looking at the source code,
>
> Error: 500
> Location: /expj2ee/ServletRedirector
> Internal Servlet Error:
>
> javax.servlet.ServletException: Missing parameter
[ServletTestRedirector_Service] in HTTP request.
>     at
j2eeunit.server.ServletTestRedirector.doPost(ServletTestRedirector.java:67)
>     at
j2eeunit.server.ServletTestRedirector.doGet(ServletTestRedirector.java:50)
>     at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
>     at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>     at
org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
>     at org.apache.tomcat.core.Handler.service(Handler.java:286)
>     at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
>     at
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797)
>     at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
>     at
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConne\
ctionHandler.java:210)
>     at
org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
>     at
org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
>     at java.lang.Thread.run(Thread.java:484)
>
>
> So I don't believe this exception is related to what I am experiencing.  I can
run other Servlets without any problem directly or via their URI defined in the
web.xml.
>
> Does anyone know what the problem may be?
>
> thanks,
> J.P.
> __________________________________________________________________
> Get your own FREE, personal Netscape Webmail account today at
http://webmail.netscape.com/
>
__________________________________________________________________
Get your own FREE, personal Netscape Webmail account today at
http://webmail.netscape.com/

#1057 From: Johannes Link <john.link@...>
Date: Fri Apr 27, 2001 3:16 am
Subject: Re: How to get a stack trace with junit.textui.TestRunner
john.link@...
Send Email Send Email
 
One possibility would be to add a TestListener to your TestResult
object. This listener could then exit the stack trace when its
addError(Test,Throwable) method is invoked. Using a test listener
requires to use Test.run(TestResult) instead of just  Test.run().

Johannes

Charles Medcoff wrote:
>
> I have found that if I write a main() for a TestCase that any asserts
> that fail give a stack trace.  For example
>
> class MyTest extends TestCase //...
> //...
>
>   public static void main(String args[])
>   {
>     MyTest my = new MyTest(//...
>     my.setUp();
>     my.testX(); // etc.
>   }
>
> However if my main looks like this
>
>   junit.textui.TestRunner.run(suite());
>
> I get no stack trace.  The trace is useful to get the linenumber in
> the source file.  Any suggestions?  (I'm currently digging through
> the docs, but please save me some time if you can.)
>
> Regards,
> Chuck

#1058 From: Lucas Filz <lucas.filz@...>
Date: Fri Apr 27, 2001 1:54 pm
Subject: excluded.properties
lucas.filz@...
Send Email Send Email
 
How does excluded.properties work ?

(I have to use -noloading and the test startup takes really long now.)

Thank you,

   Lucas

#1059 From: Joi Ellis <joi@...>
Date: Fri Apr 27, 2001 3:19 pm
Subject: Re: excluded.properties
joi@...
Send Email Send Email
 
On Fri, 27 Apr 2001, Lucas Filz wrote:

> How does excluded.properties work ?

Here's a sample from one of my test suites:


From package junit/util:
#
# The list of excluded package paths for the TestCaseClassLoader
#
excluded.0=sun.*
excluded.1=com.sun.*
excluded.2=org.omg.*
excluded.3=javax.*
excluded.4=sunw.*
excluded.5=java.*
excluded.6=junit.framework.*
excluded.7=junit.extensions.*
excluded.8=junit.swingui.*
excluded.9=junit.textui.*
excluded.10=junit.util.*
excluded.11=junit.ui.*
excluded.12=com.aravox.nsapi.subsystem.Loader

This tells Junit to let the system classloader handle anything which
patches the above packages or classes.  I use it for Loader, which
is a JNI class and which the JVM will load only once no matter what
classloader is involved.  This lets me run the Swingui for the rest
of the tests.  Loader itself I test with textui.

--
Joi Ellis                    Software Engineer
Aravox Technologies          joi@..., gyles19@...

No matter what we think of Linux versus FreeBSD, etc., the one thing I
really like about Linux is that it has Microsoft worried.  Anything
that kicks a monopoly in the pants has got to be good for something.
            - Chris Johnson

#1060 From: mlm@...
Date: Fri Apr 27, 2001 7:05 pm
Subject: Re: Long messages are truncated.
mlm@...
Send Email Send Email
 
--- In junit@y..., Robert Leftwich <digital@i...> wrote:
> At 08:18 AM 30-03-01 +0200, ERA wrote:
> >I try to use the methods "assert" and "fail" with long messages. These
> >messages are truncated after about 80 characers with the last part of the
> >message replaced by "...".
> >
> >Is it possible to change the configuration of JUnit to allow long messages
> >of about 200 charactes?
>
> In the more recent versions of JUnit (>3.2?) you can put maxmessage=-1 in a
> file called junit.properties in the user.home directory which will allow
> unlimited messages (or maxmessage=200 will do exactly what you asked for).
>

That's not enough to stop truncation in the Swing runner.  (You can see
the truncation behavior by changing the width of the JUnit window.  You
won't see a horizontal scroll bar in the list of failures until, on
Solaris under CDE, anyway, the width of the window is less than 400.)
When the JList is created in junit.swingui.FailureRunView's
constructor, setPrototypeCellValue is called.  This has the effect of
setting the preferred height and width of every element of the list to
the same value (width=297 in my environment).  Values wider than that
get truncated.

Commenting out that call to setPrototypeCellValue in
java.swingui.FailureRunView.FailureRunView(TestRunContext) fixes this
problem.  Can someone offer an argument why it should be retained?
(Does it do something else useful?)

#1061 From: kumar@...
Date: Mon Apr 30, 2001 3:19 am
Subject: Re: req for books
kumar@...
Send Email Send Email
 
hi
there is a full chapter on JUNIT3.5, the wrox press programmer to
programmer series on Professional J2EE server edition book.


regards
krishna
--- In junit@y..., Martin Wegner <marty_wegner@y...> wrote:
> JUnit is covered briefly in the "eXtreme Programming" seris as
well.  But

#1062 From: James Sinnamon <sinnamon@...>
Date: Mon Apr 30, 2001 9:16 am
Subject: what does equality mean?
sinnamon@...
Send Email Send Email
 
Sorry to have to reveal my ignorance about what must be a fundamentall
aspect of Java programming, but I cannot understand the TestCase method,
assertEquals(String message, Object expected, Object actual).

Below is some code which compares two objects, that I would have
considered to have been equal, and the output from that code:

--------------------------------------------------------
   SimpleMsg sm1 = new SimpleMsg("BronwynBishop", "AddamsFamilyValues", 53,
42,
                   MultipiMsg.BID_REQUEST);
   SimpleMsg sm2 = new SimpleMsg("BronwynBishop", "AddamsFamilyValues", 53,
42,
                   MultipiMsg.BID_REQUEST);
   assertEquals("Not Equal", sm1, sm2);

me:~/multipi:au.edu.usq.sci.multipi.TestSimpleMsg
.F
Time: 0.061
There was 1 failure:
1) testAllMethods(org.multipi.TestSimpleMsg) "Not Equal
expected:<BronwynBishopAddamsFamilyValues534216> but
was:<BronwynBishopAddamsFamilyValues534216>"

FAILURES!!!
Tests run: 1,  Failures: 1,  Errors: 0
-------------------------------------------------------

I realise that this may possibly have something to do with differnces in the

underlying pointers,  however, if this is the case, then what is the
difference
between the assertEquals() method and the  assertSame() method?

Also, is there any easy way to make comparisons between two such objects,
the contents
of which are totally identical, as I was attempting  to do?  ... or is it
necessary for me to either
either write an equals() method,  or to compare each pair of  fields
separately?

TIA

James

--
James Sinnamon  sinnamon@...

ph 07 46315566,  0412 319669
PO Box 517 Darling Heights QLD 4350

#1063 From: Fergus Gallagher <Fergus.Gallagher@...>
Date: Mon Apr 30, 2001 9:27 am
Subject: Re: what does equality mean?
Fergus.Gallagher@...
Send Email Send Email
 
calls sm1.equals(sm2), need to override

          .equals(Object o)

in SimpleMsg

At 19:16 30/04/2001 +1000, James Sinnamon wrote:
>Sorry to have to reveal my ignorance about what must be a fundamentall
>aspect of Java programming, but I cannot understand the TestCase method,
>assertEquals(String message, Object expected, Object actual).
>
>Below is some code which compares two objects, that I would have
>considered to have been equal, and the output from that code:
>
>--------------------------------------------------------
>   SimpleMsg sm1 = new SimpleMsg("BronwynBishop", "AddamsFamilyValues", 53,
>42,
>                   MultipiMsg.BID_REQUEST);
>   SimpleMsg sm2 = new SimpleMsg("BronwynBishop", "AddamsFamilyValues", 53,
>42,
>                   MultipiMsg.BID_REQUEST);
>   assertEquals("Not Equal", sm1, sm2);
>
>me:~/multipi:au.edu.usq.sci.multipi.TestSimpleMsg
>.F
>Time: 0.061
>There was 1 failure:
>1) testAllMethods(org.multipi.TestSimpleMsg) "Not Equal
>expected:<BronwynBishopAddamsFamilyValues534216> but
>was:<BronwynBishopAddamsFamilyValues534216>"
>
>FAILURES!!!
>Tests run: 1,  Failures: 1,  Errors: 0
>-------------------------------------------------------
>
>I realise that this may possibly have something to do with differnces in the
>
>underlying pointers,  however, if this is the case, then what is the
>difference
>between the assertEquals() method and the  assertSame() method?
>
>Also, is there any easy way to make comparisons between two such objects,
>the contents
>of which are totally identical, as I was attempting  to do?  ... or is it
>necessary for me to either
>either write an equals() method,  or to compare each pair of  fields
>separately?
>
>TIA
>
>James
>
>--
>James Sinnamon  sinnamon@...
>
>ph 07 46315566,  0412 319669
>PO Box 517 Darling Heights QLD 4350
>
>
>
>
>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/

--
Fergus Gallagher
Orbis
http://www.orbisuk.com/
+44-(0)20-8742 1600

#1064 From: Christian van der Leeden <leeden@...>
Date: Mon Apr 30, 2001 9:28 am
Subject: Re: what does equality mean?
leeden@...
Send Email Send Email
 
AFAIK, assertEquals compares the two objects with the equals(..) method.
You might want to implement the equals method in your SimpleMsg class
to test if all the arguments are equal. You do have access to the private
and protected fields of the other object (since it is the same type).

A+

christian

On Monday, April 30, 2001, at 11:16 AM, James Sinnamon wrote:

> Sorry to have to reveal my ignorance about what must be a fundamentall
> aspect of Java programming, but I cannot understand the TestCase method,
> assertEquals(String message, Object expected, Object actual).
>
> Below is some code which compares two objects, that I would have
> considered to have been equal, and the output from that code:
>
> --------------------------------------------------------
>   SimpleMsg sm1 = new SimpleMsg("BronwynBishop", "AddamsFamilyValues",
> 53,
> 42,
>                   MultipiMsg.BID_REQUEST);
>   SimpleMsg sm2 = new SimpleMsg("BronwynBishop", "AddamsFamilyValues",
> 53,
> 42,
>                   MultipiMsg.BID_REQUEST);
>   assertEquals("Not Equal", sm1, sm2);
>
> me:~/multipi:au.edu.usq.sci.multipi.TestSimpleMsg
> .F
> Time: 0.061
> There was 1 failure:
> 1) testAllMethods(org.multipi.TestSimpleMsg) "Not Equal
> expected:<BronwynBishopAddamsFamilyValues534216> but
> was:<BronwynBishopAddamsFamilyValues534216>"
>
> FAILURES!!!
> Tests run: 1,  Failures: 1,  Errors: 0
> -------------------------------------------------------
>
> I realise that this may possibly have something to do with differnces
> in the
>
> underlying pointers,  however, if this is the case, then what is the
> difference
> between the assertEquals() method and the  assertSame() method?
>
> Also, is there any easy way to make comparisons between two such
> objects,
> the contents
> of which are totally identical, as I was attempting  to do?  ... or is
> it
> necessary for me to either
> either write an equals() method,  or to compare each pair of  fields
> separately?
>
> TIA
>
> James
>
> --
> James Sinnamon  sinnamon@...
>
> ph 07 46315566,  0412 319669
> PO Box 517 Darling Heights QLD 4350
>
>
>
>
> 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/
>
>

#1065 From: "Scott Eade" <seade@...>
Date: Mon Apr 30, 2001 9:31 am
Subject: Re: what does equality mean?
seade@...
Send Email Send Email
 
James,

assertEquals(message, expected, actual) will ultimately test the value of:

     expected.equals(actual)

...so if your SimpleMsg class does not implement equals() then this can't be
expected to work.

assertSame(message, expected, actual) will ultimately test the value of:

     expected == actual

...so if expected and actual do not reference the same object the assertion will
fail.

Regards,

Scott
-----------------------------------
Scott Eade
Backstage Technologies Pty. Ltd.
Email: seade@...
Phone 02 9716 4090
Mobile: 0403 278 908


----- Original Message -----
From: "James Sinnamon" <sinnamon@...>
To: <junit@yahoogroups.com>
Sent: Monday, April 30, 2001 7:16 PM
Subject: [junit] what does equality mean?


> Sorry to have to reveal my ignorance about what must be a fundamentall
> aspect of Java programming, but I cannot understand the TestCase method,
> assertEquals(String message, Object expected, Object actual).
>
> Below is some code which compares two objects, that I would have
> considered to have been equal, and the output from that code:
>
> --------------------------------------------------------
>   SimpleMsg sm1 = new SimpleMsg("BronwynBishop", "AddamsFamilyValues", 53,
> 42,
>                   MultipiMsg.BID_REQUEST);
>   SimpleMsg sm2 = new SimpleMsg("BronwynBishop", "AddamsFamilyValues", 53,
> 42,
>                   MultipiMsg.BID_REQUEST);
>   assertEquals("Not Equal", sm1, sm2);
>
> me:~/multipi:au.edu.usq.sci.multipi.TestSimpleMsg
> .F
> Time: 0.061
> There was 1 failure:
> 1) testAllMethods(org.multipi.TestSimpleMsg) "Not Equal
> expected:<BronwynBishopAddamsFamilyValues534216> but
> was:<BronwynBishopAddamsFamilyValues534216>"
>
> FAILURES!!!
> Tests run: 1,  Failures: 1,  Errors: 0
> -------------------------------------------------------
>
> I realise that this may possibly have something to do with differnces in the
>
> underlying pointers,  however, if this is the case, then what is the
> difference
> between the assertEquals() method and the  assertSame() method?
>
> Also, is there any easy way to make comparisons between two such objects,
> the contents
> of which are totally identical, as I was attempting  to do?  ... or is it
> necessary for me to either
> either write an equals() method,  or to compare each pair of  fields
> separately?
>
> TIA
>
> James
>
> --
> James Sinnamon  sinnamon@...
>
> ph 07 46315566,  0412 319669
> PO Box 517 Darling Heights QLD 4350
>
>
>
>
> 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/
>
>

#1066 From: Jim Cheesman <jchees@...>
Date: Mon Apr 30, 2001 9:44 am
Subject: Re: what does equality mean?
jchees@...
Send Email Send Email
 
At 11:16 AM 4/30/2001, you wrote:
>Sorry to have to reveal my ignorance about what must be a fundamentall
>aspect of Java programming, but I cannot understand the TestCase method,
>assertEquals(String message, Object expected, Object actual).


I think you need to override Object.equals() to be able to use this method
correctly: according to the api, the implementation of equals() in Object
is such that the references are the same, i.e o1 == o2. This is obviously
not the case in the example you give below.


(Of course, I could be wrong here....)


Jim


>Below is some code which compares two objects, that I would have
>considered to have been equal, and the output from that code:
>
>--------------------------------------------------------
>   SimpleMsg sm1 = new SimpleMsg("BronwynBishop", "AddamsFamilyValues", 53,
>42,
>                   MultipiMsg.BID_REQUEST);
>   SimpleMsg sm2 = new SimpleMsg("BronwynBishop", "AddamsFamilyValues", 53,
>42,
>                   MultipiMsg.BID_REQUEST);
>   assertEquals("Not Equal", sm1, sm2);
>
>me:~/multipi:au.edu.usq.sci.multipi.TestSimpleMsg
>.F
>Time: 0.061
>There was 1 failure:
>1) testAllMethods(org.multipi.TestSimpleMsg) "Not Equal
>expected:<BronwynBishopAddamsFamilyValues534216> but
>was:<BronwynBishopAddamsFamilyValues534216>"
>
>FAILURES!!!
>Tests run: 1,  Failures: 1,  Errors: 0
>-------------------------------------------------------
>
>I realise that this may possibly have something to do with differnces in the
>
>underlying pointers,  however, if this is the case, then what is the
>difference
>between the assertEquals() method and the  assertSame() method?
>
>Also, is there any easy way to make comparisons between two such objects,
>the contents
>of which are totally identical, as I was attempting  to do?  ... or is it
>necessary for me to either
>either write an equals() method,  or to compare each pair of  fields
>separately?
>
>TIA
>
>James
>
>--
>James Sinnamon  sinnamon@...
>
>ph 07 46315566,  0412 319669
>PO Box 517 Darling Heights QLD 4350
>
>
>
>
>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/


--

                            *   Jim Cheesman   *
              Trabajo:
jchees@... - (34)(91) 724 9200 x 2360
                Personal:
mogrim@... (34) 606 770 244
             Prepositions are not words
to end sentences with.

#1067 From: James Sinnamon <sinnamon@...>
Date: Mon Apr 30, 2001 9:58 am
Subject: Re: what does equality mean?
sinnamon@...
Send Email Send Email
 
Thanks everyone for your very timely and helpful responses.  I actually did have

an equals() method in SimpleMsg,  but when I looked more closely, I realised
that
the argument should have been of type Object rather than of type 'SimpleMsg'.

So I guess this means that I do have to write equals() methods then if I want to
use
assertEquals().

Thanks again,

regards,

James


Jim Cheesman wrote:

> At 11:16 AM 4/30/2001, you wrote:
> >Sorry to have to reveal my ignorance about what must be a fundamentall
> >aspect of Java programming, but I cannot understand the TestCase method,
> >assertEquals(String message, Object expected, Object actual).
>
> I think you need to override Object.equals() to be able to use this method
> correctly: according to the api, the implementation of equals() in Object
> is such that the references are the same, i.e o1 == o2. This is obviously
> not the case in the example you give below.
>
> (Of course, I could be wrong here....)
>
> Jim
>
> >Below is some code which compares two objects, that I would have
> >considered to have been equal, and the output from that code:
> >
> >--------------------------------------------------------
> >   SimpleMsg sm1 = new SimpleMsg("BronwynBishop", "AddamsFamilyValues", 53,
> >42,
> >                   MultipiMsg.BID_REQUEST);
> >   SimpleMsg sm2 = new SimpleMsg("BronwynBishop", "AddamsFamilyValues", 53,
> >42,
> >                   MultipiMsg.BID_REQUEST);
> >   assertEquals("Not Equal", sm1, sm2);
> >
> >me:~/multipi:au.edu.usq.sci.multipi.TestSimpleMsg
> >.F
> >Time: 0.061
> >There was 1 failure:
> >1) testAllMethods(org.multipi.TestSimpleMsg) "Not Equal
> >expected:<BronwynBishopAddamsFamilyValues534216> but
> >was:<BronwynBishopAddamsFamilyValues534216>"
> >
> >FAILURES!!!
> >Tests run: 1,  Failures: 1,  Errors: 0
> >-------------------------------------------------------
> >
> >I realise that this may possibly have something to do with differnces in the
> >
> >underlying pointers,  however, if this is the case, then what is the
> >difference
> >between the assertEquals() method and the  assertSame() method?
> >
> >Also, is there any easy way to make comparisons between two such objects,
> >the contents
> >of which are totally identical, as I was attempting  to do?  ... or is it
> >necessary for me to either
> >either write an equals() method,  or to compare each pair of  fields
> >separately?
> >
> >TIA
> >
>

<snip>


--
James Sinnamon  sinnamon@...

ph 07 46315566,  0412 319669
PO Box 517 Darling Heights QLD 4350

#1068 From: Ilja Preu? <I.Preuss@...>
Date: Mon Apr 30, 2001 10:09 am
Subject: AW: what does equality mean?
I.Preuss@...
Send Email Send Email
 
> Sorry to have to reveal my ignorance about what must be a fundamentall
> aspect of Java programming, but I cannot understand the
> TestCase method,
> assertEquals(String message, Object expected, Object actual).

http://www.javaworld.com/javaworld/jw-10-1998/jw-10-techniques.html
discusses - besides some other general issues - why and how you should
implement the equals() method.

Hope this helps,

Ilja

#1069 From: pholser@...
Date: Mon Apr 30, 2001 12:57 pm
Subject: Re: what does equality mean?
pholser@...
Send Email Send Email
 
<james>
> Thanks everyone for your very timely and helpful responses.  I
> actually did have an equals() method in SimpleMsg,  but when I
> looked more closely, I realised that the argument should have
> been of type Object rather than of type 'SimpleMsg'.
</james>

right...the reason you don't want to write equals(YourClass) is that
if you stuff an instance of YourClass in, say, a collection, then
go searching for it, it won't be equals(YourClass) called by the
collection class to report equality, but equals(Object).  if you
don't define equals(Object), then the version supplied by Object
itself is invoked, and that's usually not what you mean.

cheers,
p

#1070 From: David Roussel <dir@...>
Date: Mon Apr 30, 2001 1:03 pm
Subject: FW: Re: what does equality mean?
dir@...
Send Email Send Email
 
I tend to write equals(YourClass) first and then write equals(Object) to test type of argument, cast to YourClass, and then call equals(YourClass).
-----Original Message-----
From: pholser@... [mailto:pholser@...]
Sent: 30 April 2001 13:57
To: junit@yahoogroups.com
Subject: [junit] Re: what does equality mean?

<james>
> Thanks everyone for your very timely and helpful responses.  I
> actually did have an equals() method in SimpleMsg,  but when I
> looked more closely, I realised that the argument should have
> been of type Object rather than of type 'SimpleMsg'.
</james>

right...the reason you don't want to write equals(YourClass) is that
if you stuff an instance of YourClass in, say, a collection, then
go searching for it, it won't be equals(YourClass) called by the
collection class to report equality, but equals(Object).  if you
don't define equals(Object), then the version supplied by Object
itself is invoked, and that's usually not what you mean.

cheers,
p




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.

-------------------------------------------------------------------------
NOTICE - PRIVATE & CONFIDENTIAL
This e-mail and any attachments are intended solely for use by the
addressee. Their contents may be legally privileged, confidential or
otherwise protected from disclosure. If you are not the addressee please
be advised that any use whatsoever of this e-mail (including any reliance
upon its contents) is strictly prohibited. No liability is accepted by
BJSS Limited for any loss whatsoever arising from any use of any
information contained in this e-mail.
If you have received this e-mail in error please notify BJSS Limited
immediately by telephone on 0113 2979797 or by return of e-mail, and
delete this e-mail.

WARNING
It is the responsibility of the recipient to ensure that any use of this
e-mail and any attachments will not adversely effect its systems or data.
Please carry out such file checks and other checks as appropriate.
No responsibility is accepted by BJSS Limited in this regard.
------------------------------------------------------------------------



-------------------------------------------------------------------------
NOTICE - PRIVATE CONFIDENTIAL
This e-mail and any attachments are intended solely for use by the
addressee. Their contents may be legally privileged, confidential or
otherwise protected from disclosure. If you are not the addressee please
be advised that any use whatsoever of this e-mail (including any reliance
upon its contents) is strictly prohibited. No liability is accepted by
BJSS Limited for any loss whatsoever arising from any use of any
information contained in this e-mail.
If you have received this e-mail in error please notify BJSS Limited
immediately by telephone on 0113 2979797 or by return of e-mail, and
delete this e-mail.

WARNING
It is the responsibility of the recipient to ensure that any use of this
e-mail and any attachments will not adversely effect its systems or data.
Please carry out such file checks and other checks as appropriate.
No responsibility is accepted by BJSS Limited in this regard.
------------------------------------------------------------------------



#1071 From: Keith Ray <keith.ray@...>
Date: Mon Apr 30, 2001 6:02 pm
Subject: re - equals method
keith.ray@...
Send Email Send Email
 

The book "Practical Java" by Haggar explains why you should probably want to do your equals method this way:

class Worker extends Person
{
....
public boolean equals(Object o)
{
  if (o == null)
  {
    return false;
  }
  if ( o.getClass().equals( this.getClass() ) )
  {
    Worker w = (Worker) o;
    return name.equals( w.name ) && doList.equals( w.doList );
  }
  return false;
}

...
}


#1072 From: David Li <david@...>
Date: Mon Apr 30, 2001 7:02 pm
Subject: Re: Junit and Log4j (Use AspectJ)
david@...
Send Email Send Email
 
Hi Matt,

   I just about to posting something related to this subject. We use both
Log4J and JUnit intensively in our codes. Before, we used a modified
TestRunner that initialize Log4J properly and log the result to Log4J.
This modification is not very clean and causes headache in tracking new
Log4J version.

   We start using AspectJ (www.aspectj.org). It's a Aspect Oriented
Programming in Java to deal with point cut concern. For detail, please
read the aspectj page. With AspectJ, we are able to integrate Log4J with
JUnit with a simple Aspect as the following:

---
package junit.aspect;

aspect Log4JRunner {

     /* catch the main method of three TestRunner */
     pointcut runnerMain():
         executions(public static void
junit.awtui.TestRunner.main(String[])) ||
         executions(public static void
junit.textui.TestRunner.main(String[])) ||
         executions(public static void
junit.swingui.TestRunner.main(String[]));

     /* initialize the log4j before executing any codes in main method */
     before(): runnerMain() {
         org.apache.log4j.BasicConfigurator.configure();

org.apache.log4j.Category.getRoot().setPriority(org.apache.log4j.Priority.DEBUG)\
;
     }
}
---

With that simple aspect, we now have all three TestRunner from JUnit
properly initialize Log4J!

To archive your goal on logging test result to Log4J, you can just write
asepct to trap startTest, addError and addFailure in the test runner and
log the event to Log4J.

David Li
DigitalSesame

Matthew Bertrand wrote:
>
> Hi everyone,
>
> I'm having trouble figuring out how to use Junit in conjunction with Log4j
> for logging test results.  Does anyone have experience with this, or with
> redirecting Junit output in general?
>
> Any help appreciated,
>
> Matt
>
> 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/

#1073 From: David Li <david@...>
Date: Mon Apr 30, 2001 7:23 pm
Subject: On extending JUnit with AspectJ...
david@...
Send Email Send Email
 
Hi,

   I think I just found a solution to my long time problem with JUnit. We
do development mostly on server side components and most of these server
side classes need to run with the server context properly setup.

   Setting up these server contxt often involve using specialized
classloader to load the class. Using JUnit's native test runner often
conflict with these classloader. ;(

   We end up have to write our implementation of TestRunner for each of
these environment and we often have to implement all three TestRunners.
The work is tedious and this makes tracking new version of JUnit a lot
harder. :(

   There doesn't seem to be a good Object Oriented Java based solution to
this problem. The problem of having to adapt each TestRunner to specific
environment will requires extending all three TestRunner at the same
time and have to call the class different names.

   Aspect Oriented Programming (www.aspectj.org) seem to solve this
problem elegantly. The following is a quick sample codes on adapting
Log4J into JUnit which extending all three TestRunner in one file.

   The problem: We use Log4J in our components and JUnit to unit test of
the components. The problem is that Log4J need to be initialized at
least once from the main method. Doing it in a OO way will require us to
extending all three TestRunner to something like

public class TestRunnerWithLog4J extends junit.awtui.TestRunner
{
     public static void main(String[] args) {
         Log4J_INIT_CODES_HERE;
         super.main(args);
     }
}

   Second problem we are having is that we need to document the fact and
make our developers aware what TestRunner to be use with what framework.
We now have three versions of TestRunner:

TestRunnerWithEnhydra, TestRunnerWithOzone and TestRunnerWithLog4.

In this case, Ozone uses Log4J as well. The list grows very fast and the
extensions codes become a big tangled codes and maintaince hell!

AspectJ seems to provide a very elegant solution to this. The following
is my first try to use AspectJ to solve this problem:

---
package junit.aspect;

aspect Log4JRunner {

     pointcut runnerMain():
         executions(public static void
junit.awtui.TestRunner.main(String[])) ||
         executions(public static void
junit.textui.TestRunner.main(String[])) ||
         executions(public static void
junit.swingui.TestRunner.main(String[]));

     before(): runnerMain() {
         org.apache.log4j.BasicConfigurator.configure();

org.apache.log4j.Category.getRoot().setPriority(org.apache.log4j.Priority.DEBUG)\
;
     }
}
---

This aspect simply extending the main method in each TestRunner to
properly initialize the Log4J. This extension gives three main
advantages:

1. No modification to the original JUnit codes
2. No messy subclass of TestRunner to maintaine.
3. No special documents for each TestRunner for each environment.

I'd like to get the opinion of the JUnit users and developers on using
AOP as the extension proramming for JUnit.

Thanks.

David Li
DigitalSesame

#1074 From: "Charles Medcoff" <cmedcoff@...>
Date: Mon Apr 30, 2001 8:00 pm
Subject: Re: [ANNOUNCE] Cactus 1.0 beta 1
cmedcoff@...
Send Email Send Email
 
Vincent,

I've grabbed the beta two and after some struggles have gotton the
sample to run.  However I don't understand how the tests are getting
invoked using Ant.  We are currently using make rather than Ant for
our builds :(

How do I invoke the tests from either the command-line (or GUI
version) of JUnit?  For the sample I've tried

java junit.textui.TestRunner
org.apache.commons.cactus.sample.TestSampleServlet, but I get the
following error message.

Class definition "org.apache.commons.cactus.sample.TestSampleServlet"
not found.

I'm running this in the classes dir created by the build.xml file and
I know that "." is on my classpath so I can't see how the classpath
is the problem.

Any suggestions would be greatly appreciated.

Best Regards,
Chuck

Messages 1045 - 1074 of 24393   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