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 3156 - 3185 of 24384   Oldest  |  < Older  |  Newer >  |  Newest
Messages: Show Message Summaries Sort by Date ^  
#3156 From: "MiChAeL xEnAkIs" <mgxenakis@...>
Date: Thu Nov 1, 2001 10:37 pm
Subject: startTest(...)/endTest(...)... does what?
mgxenakis
Send Email Send Email
 
Hey JUniter's -
 
Still in the preliminary stages of investigating the various functional aspects of the JUnit framework(s) and have come across the following question(s).
 
I'm using the TestResult(s) object to gather results as I go - given the assumption that a failure early in the test may not invalidate code-execution later in the test.  (I know, such an assumption begs for refactoring, but let us ignore that fact for a moment. ;-)
 
I've added a TestResult(s) instance variable to my TestCase fixture, which I use in each of the Test(s) for gather results.  The TestResult API says the following for these two methods:
startTest(Test t) - Informs the result that a test will be started.
endTest(Test t) - Informs the results that a test was completed.
 
What precisely does this mean, and what effect does this have on the results (failures, errors, etc.) which the result compiles during execution of the test(s)?
 
I'm trying various test runs, some which call start/endTest(...) multiple times, some only once, and some which don't call these at all.  Ultimately, however, I see no difference in the output of my tests when executed.
 
Further, the errros/failures reported when the fixture finishes execution seems to ignore the TestResult object which I've created and am using.  I.e., in the case of multi-failures/errors in a single test, I add them all to my TestResult instance, however, the end results - e.g. when a single test has more than one assertEquals(...) failure - will only report the last failure it encounters (which kinda makes sense, as there would, otherwise, possibly be more failures listed than the actual number of tests.)
 
Am I simply trying to misuse the TestResult(s) object?
 
thanks for any info on this
mx.
 
"When a relationship is not built on mutual respect,
 the only way of maintaining control is through brutal force."
 -- Roger Fouts

#3157 From: "J. B. Rainsberger" <jbrains762@...>
Date: Thu Nov 1, 2001 11:09 pm
Subject: RE: Re: Behavior of tearDown and exceptions
nails762
Send Email Send Email
 
> Thanks for the reply.  Your proposed solution would not solve the problem
I
> am trying to address.  My situation is the following:
>
> 1. My test method throws an exception.  This exception indicates the real
> problem.
> 2. My tearDown method throws an exception.  This exception is caused by an
> invalid state because my test method did not run all way through.
>
> This is a problem because of #2.  The way the JUnit framework is written,
> any exception coming out of tearDown will mask any exception coming out of
a
> test method.

As Kent would say, this sounds like an opportunity to improve your design.
Is there something you can do about tearDown() so that it doesn't throw an
exception whenever the test fails? Any code that tears down fixture should
really only fail if there's a low-level problem you can't control (network
transport, database connection, that kind of thing). Maybe you're doing too
much to set up and tear down your test fixture.

JBR.

#3158 From: "J. B. Rainsberger" <jbrains762@...>
Date: Thu Nov 1, 2001 11:12 pm
Subject: JUnit root directory question
nails762
Send Email Send Email
 
> Hello -
>
> When I run JUnit, where does it consider the top or root level directory?

I found it better to avoid the problem entirely. You should not let yourself
rest at the whim of the JUnit developers, nice guys though they are.
Consider passing a JVM property to the TestRunner like "test.root" and use
THAT as your "root".

Example:

java -Dtest.root=c:/myRoot junit.textui.TestRunner MyTestCase

public class MyTestCase extends TestCase {
     ...
     protected File root() {
         return new File(System.getProperty("test.root", "/"));
     }
     ....
     public void testSomething() {
         File button = new File(root(), "/images/testcases/button.gif");
         ....
     }
}

You can use the File object to create an absolute path from your relative
paths.

What do you think? Now your tests run anywhere and you can put the files you
need anywhere.

JBR.

#3159 From: infosuresh@...
Date: Fri Nov 2, 2001 10:03 am
Subject: the complete process.
infosuresh@...
Send Email Send Email
 
HAI,
     Designing the whole test process.

Step1:subclass the TestCase.
Step2:Initailize
Step3:Add testXXX() methods.
Step4:If reqiured run repeated tests.
Step5:Collect Result in Junit coding itself using TestResult
Step6:tearDown.

Can anyone send an illustrated code example for the above the  testing process.
This will help in understanding the junit in a better way for newbie's.

thank u & regards
Suresh.S


-------------------------------------------------
This mail helped a tree grow. Know more at http://green.sify.com

Want to win a PC or Palm Tops or Digital Diaries or T-Shirts?
Click here http://promos.sify.com/niit/main.asp?mail

#3160 From: Berin Loritsch <bloritsch@...>
Date: Fri Nov 2, 2001 2:54 pm
Subject: ClassLoader issues and JUnit
bloritsch
Send Email Send Email
 
One thing that I see often is the fact that JUnit works
from the command line, but not from the swing version.
Veterans of JUnit are aware that this is a classloader
issue.  There is a way to turn off the new classloader
per test behavior.

I assert that this is not a proper testing environment.
It is not analogous to real situations, and leads to
false negatives.  No real world classloader environment
I am aware of behaves like that of JUnit's Swing
TestRunner.  What this leads people to do is work around
the buggy classloader.  This is not what should be
happening IMNSHO.

I propose that JUnit should provide a consistent
classloading environment, or scrap the whole alternate
ClassLoader environment altogether.  I consider it a
bug in the test framework if the results of the test
are different based on how I execute the TestRunner.
This needs to be remedied soon.  The ClassLoader is
buggy if it does not behave according to normal
classloaders (like URLClassLoader as the yardstick).

--

"Those who would trade liberty for
  temporary security deserve neither"
                 - Benjamin Franklin

#3161 From: Robert Sartin <sartin@...>
Date: Fri Nov 2, 2001 3:01 pm
Subject: Re: ClassLoader issues and JUnit
robert_sartin
Send Email Send Email
 
--- Berin Loritsch <bloritsch@...> wrote:
> I assert that this is not a proper testing environment.
> It is not analogous to real situations, and leads to
> false negatives.  No real world classloader environment

I assert that it is almost a proper testing environment. For many, if
not most, JUnit users, the class loading tests work and work better
than the alternative because they allow a developer to leave the Swing
UI running and rerun an individual test after changing it in the IDE.
As the usage of JUnit expans, many people run the Swing UI in what I
would consider strange environments. I often wonder why they aren't
just running the textui, but I digress. Since those environment are
common, and the loading behavior introduces problems it would probably
be best to change the Swing UI to default to noloading. Eliminating the
class loading behavior would be a huge disservice to the devlopers who
use it daily to increase their feedback by running tests while coding.

Regards,

Rob


__________________________________________________
Do You Yahoo!?
Find a job, post your resume.
http://careers.yahoo.com

#3162 From: Berin Loritsch <bloritsch@...>
Date: Fri Nov 2, 2001 3:12 pm
Subject: Re: ClassLoader issues and JUnit
bloritsch
Send Email Send Email
 
Robert Sartin wrote:
>
> --- Berin Loritsch <bloritsch@...> wrote:
> > I assert that this is not a proper testing environment.
> > It is not analogous to real situations, and leads to
> > false negatives.  No real world classloader environment
>
> I assert that it is almost a proper testing environment. For many, if
> not most, JUnit users, the class loading tests work and work better
> than the alternative because they allow a developer to leave the Swing
> UI running and rerun an individual test after changing it in the IDE.
> As the usage of JUnit expans, many people run the Swing UI in what I
> would consider strange environments. I often wonder why they aren't
> just running the textui, but I digress. Since those environment are
> common, and the loading behavior introduces problems it would probably
> be best to change the Swing UI to default to noloading. Eliminating the
> class loading behavior would be a huge disservice to the devlopers who
> use it daily to increase their feedback by running tests while coding.

"Almost" and "Are" can sometimes be a mile apart.  Defaulting to the
"-nonloading" option is a step in the right direction.  However, what
about this possibility:

The same classloader is run for all tests.  When the Swing runner is asked
to re-run a test or group of tests, create a new Classloader for the
environment.

The important thing here is consistency.  In this situation, we do not
have a new ClassLoader for each individual *Test* (which may be simply
another method in the same class).  We have a new ClassLoader for each
individual *Run*.  This provides the flexibility the users want, AND
the stable environment everyone craves.

Have you guys considered that route and run into snags?

--

"Those who would trade liberty for
  temporary security deserve neither"
                 - Benjamin Franklin

#3163 From: Earl Hokens <earl.hokens@...>
Date: Fri Nov 2, 2001 9:13 pm
Subject: How to test
earl.hokens@...
Send Email Send Email
 
I have a couple of testing best practices questions for the group.

If I am doing operator overloading (polymorphism) what is an acceptable
way to construct the tests in JUnit so that I can tell which method
passes or fails?  For example:
	 int add(int a, int b){
		 return (a+b);
	 }

	 double add(double a, double b) {
		 return (a+b);
	 }

	 float add(float a, float b) {
		 return (a+b);
	 }

I need a test called testAdd().  I have to test all of them from this
method right?  How I can which one fails?

My next question has to do with testing sub classes.  If I have a
framework api with a class, MyBaseClass, and in a project I define
MyProjectClass extends MyBaseClass.  Would you want to write tests for
methods defined in MyBaseClass?  Is this situation dependant or should
you never/always write them?

Thanks,
Earl
earl.hokens@...

#3164 From: Eric Vought <evought@...>
Date: Fri Nov 2, 2001 9:48 pm
Subject: Re: How to test
eric_vought
Send Email Send Email
 
On Fri, 2 Nov 2001, Earl Hokens wrote:

> I have a couple of testing best practices questions for the group.
>
> If I am doing operator overloading (polymorphism) what is an acceptable
> way to construct the tests in JUnit so that I can tell which method
> passes or fails?  For example:
>  int add(int a, int b){
> 	 return (a+b);
>  }
>
>  double add(double a, double b) {
> 	 return (a+b);
>  }
>
>  float add(float a, float b) {
> 	 return (a+b);
>  }
>
> I need a test called testAdd().  I have to test all of them from this
> method right?  How I can which one fails?

Your test methods don't have to mathc your method names. In other words,
there is no restriction that testAdd() and only testAdd() tests the method
"add". We use the method name as a base and then add additional info to
it:

testAddIntInt()
testAddDoubleDouble()

Typically, you will have more than one test per method, testing different
entry conditions:

testEqualsEmptyInstance()
testEqualsWNull()
testEqualsWIdentity()

etc.

> My next question has to do with testing sub classes.  If I have a
> framework api with a class, MyBaseClass, and in a project I define
> MyProjectClass extends MyBaseClass.  Would you want to write tests for
> methods defined in MyBaseClass?  Is this situation dependant or should
> you never/always write them?

If we control the base class, we always write an abstract TestCase when we
write the base class. If it is a third party base class (or interface),
then we will often create an appropriate abstract TestCase against their
base class, though sometimes we will go back and add it later in a round
of refactoring. With standard library classes, it is convenient to keep a
small collection of abstract TestCases somewhere that can be reused from
project to project (e.g. for Enumeration, Iterator, Collection).

Creating the test case for a 3rd party base class accomplishes two
things. You can run the test (possibly with the help of a trivial stub)
against their code to detect bugs, misunderstandings, and behavior
changes. You also get a much better indication that the classes you create
will interact correctly with their library (or, at least, that you can
demonstrate where the fault lies). Implementing this test case can be used
as a first exploration of a new toolkit/base class to ensure that you
understand both what it is supposed to do and what it actually does
before you build your code around it.

>
> Thanks,
> Earl
> earl.hokens@...
>
>
> 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/
>
>
>

--
Eric Vought
Chief Technical Officer - QLUE Consulting, Inc.

evought@... toll-free: 888-771-3538  RTP area: 919-816-9901

#3165 From: infosuresh@...
Date: Sat Nov 3, 2001 10:04 am
Subject: printing results
infosuresh@...
Send Email Send Email
 
hai,

     After storing the result in an object of type  Test
Result..what is the method that can be used to print it?
Can anyone expalin?

Thank U & Regards
Suresh.S

-------------------------------------------------
This mail helped a tree grow. Know more at http://green.sify.com

Want to win a PC or Palm Tops or Digital Diaries or T-Shirts?
Click here http://promos.sify.com/niit/main.asp?mail

#3166 From: "J. B. Rainsberger" <jbrains762@...>
Date: Sat Nov 3, 2001 2:53 pm
Subject: Subject: printing results
nails762
Send Email Send Email
 
> hai,
>
>     After storing the result in an object of type  Test
> Result..what is the method that can be used to print it?
> Can anyone expalin?
>
> Thank U & Regards
> Suresh.S

Have you looked at both the API documentation and the source that comes with
JUnit? If it's not there, and you can't do it yourself, it can't be done.

JBR.

#3167 From: "FrankSun" <franksun@...>
Date: Mon Nov 5, 2001 6:51 am
Subject: Who can tell me the scape of unit test of class.
leafsun2001
Send Email Send Email
 
I do not know if all the class should do unit test.
Some class do not process the real action espc in the large framework.
thx!
 
 
+===================================================+
+======     Contact: Frank                     =====+
+======     Email: franksun@...        =====+
+======     Tel: 86-0755,6821727               =====+
+======    ********************************    =====+
+======     Software Quality Assurance         =====+
+======       Dichain System Limited           =====+
+===================================================+

#3168 From: "Paolo Perrotta" <pperrotta@...>
Date: Mon Nov 5, 2001 9:29 am
Subject: Re: Who can tell me the scape of unit test of class.
pperrotta@...
Send Email Send Email
 
Can you submit an example of a class that you think should *not* be unit tested?
 
-----
I do not know if all the class should do unit test.
Some class do not process the real action espc in the large framework.

#3169 From: Steve Gardell <sgardell@...>
Date: Mon Nov 5, 2001 11:30 am
Subject: RE: Who can tell me the scape of unit test of class.
sgardell@...
Send Email Send Email
 
Maybe the question is better "independently unit tested." It is not
unusual to define helper classes such as "value classes" or
"enumeration classes." IMHO, adequate test coverage for helper
classes is generally achieved via the unit tests that address logic/state-
management classes that in turn use these helper classes.
-----Original Message-----
From: Paolo Perrotta [mailto:pperrotta@...]
Sent: Monday, November 05, 2001 4:29 AM
To: junit@yahoogroups.com
Subject: Re: [junit] Who can tell me the scape of unit test of class.

Can you submit an example of a class that you think should *not* be unit tested?
 
-----
I do not know if all the class should do unit test.
Some class do not process the real action espc in the large framework.

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.

#3170 From: "Paolo Perrotta" <pperrotta@...>
Date: Mon Nov 5, 2001 12:26 pm
Subject: Re: Who can tell me the scape of unit test of class.
pperrotta@...
Send Email Send Email
 
Agreed, but I get there in steps. I tend to unit test nearly everything directly and independently when I write it (excluded very, very simple classes - such as exceptions). I don't care at first if a class is an helper class, or even an abstract class.
 
An example with an abstract class (the same reasoning goes for helper classes):
 
1) I write an abstract class Abstract.
2) As soon as Abstract is done, I write a concrete test subclass ConcreteForTesting that extends it.
3) I unit-test ConcreteForTesting.
 
4) After that, I'll probably write a production subclass of Abstract (let's call it Production).
5) If the testing of Production is a superset of the testing of ConcreteForTesting, I refactor the unit test of ConcreteForTestingto test Production instead.
6) I delete ConcreteForTesting. At this point I'm only testing Abstract indirectly.
 
(5) and (6) don't always happen.
Of course I might be paranoid. :)  But I feel better knowing that at any given time, everything in the system is stable and tested.
Maybe the question is better "independently unit tested." It is not
unusual to define helper classes such as "value classes" or
"enumeration classes." IMHO, adequate test coverage for helper
classes is generally achieved via the unit tests that address logic/state-
management classes that in turn use these helper classes.
Can you submit an example of a class that you think should *not* be unit tested?
    ---------------------
    Paolo Perrotta
    Bologna, Italy

#3171 From: "Daniel Reynes" <daniel.reynes@...>
Date: Mon Nov 5, 2001 3:27 pm
Subject: Catching a stop program in JBuilder
dandandrfr
Send Email Send Email
 

I use JBuilder 4 to run some tests with Juint.

Sometimes I want to stop running these tests and I use the Stop button of JBuilder.

But I would like to catch this action in order to be able to stop the tests where I want.

 

Does anybody know how to do this ?

 

Dan

 

P.S. Sorry if this is not the good place to ask this kind of question.


#3172 From: "DiFrango, Ron" <ron.difrango@...>
Date: Mon Nov 5, 2001 4:41 pm
Subject: RE: jUnit bug? textui - no errors, gui - errors.
difranr
Send Email Send Email
 
>> can't find any junit.properties file on the system.
>> Do you have any information about this?

I am not sure if you got your answer, but JUnit looks for that file to be in
a system environment variable called user.home.  One Windows 2000 (and I
suspect NT) this maps to the environment variable: USERPROFILE.  Just store
the file there and it works fine.

Another alternative is to in essence over-ride by setting this on the java
call like the following:

	 java -Duser.home=c:\temp My_TEST

If you do not want to override this variable, the you can change the code in
the junit.runner.BaseTestRunner's getPreferencesFile() method to use your
own defined method.

Personally, I think that JUnit should use something like junit.home for this
variable because on Windows platforms you typically do not work out of your
home directory like you do on Unix.

Ron DiFrango

-----Original Message-----
From: Bret Waldow [mailto:Bret.Waldow@...]
Sent: Monday, October 29, 2001 7:45 PM
To: 'junit@yahoogroups.com'
Subject: RE: [junit] jUnit bug? textui - no errors, gui - errors.


>> can't find any junit.properties file on the system.
>> Do you have any information about this?

> My system has one. I assume JUnit creates it automatically. Perhaps you
have
> an old version of JUnit, or maybe the directory that Java thinks is your
home
> directory isn't writable.

Odd.  I'm running jUnit 3.7, and the permissions on my local directory in
WINNT\Profile are open to all.

I suspect the system might maintain some network directory as my "home" that
I don't know about?

Bret


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/


**************************************************************************
The information transmitted herewith is sensitive information intended only
for use by the individual or entity to which it is addressed. If the reader
of this message is not the intended recipient, you are hereby notified that
any review, retransmission, dissemination, distribution, copying or other
use of, or taking of any action in reliance upon this information is
strictly prohibited. If you have received this communication in error,
please contact the sender and delete the material from your computer.

#3173 From: Russ Baker <rbaker@...>
Date: Mon Nov 5, 2001 4:45 pm
Subject: RE: Catching a stop program in JBuilder
rbaker@...
Send Email Send Email
 
use the breakpoint.
-----Original Message-----
From: Daniel Reynes [mailto:daniel.reynes@...]
Sent: Monday, November 05, 2001 8:27 AM
To: Junit
Subject: [junit] Catching a stop program in JBuilder

I use JBuilder 4 to run some tests with Juint.

Sometimes I want to stop running these tests and I use the Stop button of JBuilder.

But I would like to catch this action in order to be able to stop the tests where I want.

 

Does anybody know how to do this ?

 

Dan

 

P.S. Sorry if this is not the good place to ask this kind of question.



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.

#3174 From: "Kelso, JP Phil (5502)" <kelsojp@...>
Date: Mon Nov 5, 2001 4:54 pm
Subject: RE: Who can tell me the scape of unit test of class.
kelsojp@...
Send Email Send Email
 
How about a class that can't possibly break?  Say a class with only setters
and getters?

> ----------
> From:  Paolo Perrotta[SMTP:pperrotta@...]
> Reply To:  junit@yahoogroups.com
> Sent:  Monday, November 05, 2001 3:29 AM
> To:  junit@yahoogroups.com
> Subject:  Re: [junit] Who can tell me the scape of unit test of class.
>
> Can you submit an example of a class that you think should *not* be unit
> tested?
>
>
>  -----
>
>  I do not know if all the class should do unit test.
>  Some class do not process the real action espc in the large
> framework.
>
>
> 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/>.
>

#3175 From: "Heath, Joseph" <HeathJ@...>
Date: Mon Nov 5, 2001 5:04 pm
Subject: RE: Who can tell me the scape of unit test of class.
mbcx4jrh
Send Email Send Email
 
Can still break - only through extremely silly error maybe , but nonetheless
if you were relying on your unit tests to show error this could mess you up
for a bit..
Yes, this is experience talking..;-)
joe

> -----Original Message-----
> From: Kelso, JP Phil (5502) [mailto:kelsojp@...]
> Sent: 05 November 2001 16:55
> To: 'junit@yahoogroups.com'
> Subject: RE: [junit] Who can tell me the scape of unit test of class.
>
>
> How about a class that can't possibly break?  Say a class
> with only setters
> and getters?
>
> > ----------
> > From:  Paolo Perrotta[SMTP:pperrotta@...]
> > Reply To:  junit@yahoogroups.com
> > Sent:  Monday, November 05, 2001 3:29 AM
> > To:  junit@yahoogroups.com
> > Subject:  Re: [junit] Who can tell me the scape of unit
> test of class.
> >
> > Can you submit an example of a class that you think should
> *not* be unit
> > tested?
> >
> >
> >  -----
> >
> >  I do not know if all the class should do unit test.
> >  Some class do not process the real action espc in the large
> > framework.
> >
> >
> > 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/>.
> >
>
> 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/
>
>

This e-mail and any attachment is for authorised use by the intended
recipient(s) only.  It may contain proprietary material, confidential
information and/or be subject to legal privilege.  It should not be copied,
disclosed to, retained or used by, any other party.  If you are not an intended
recipient then please promptly delete this e-mail and any attachment and all
copies and inform the sender.  Thank you.

#3176 From: Eric Vought <evought@...>
Date: Mon Nov 5, 2001 6:11 pm
Subject: RE: Who can tell me the scape of unit test of class.
eric_vought
Send Email Send Email
 
Your test case verifies that you don't lose functionality.
Simple classes can break too. Especially if you use cut and paste to
create the setters/getters:

public class Point
{
	 private int d_x;
	 private int d_y;

	 public int getX() {return d_x;}
	 public void setX(int x) {d_x = x;}

	 public int getY() {return d_y;}
	 public void setY(int y) {d_x = y;}
} // class Point

There is also the possibility that the simple class will become more
complex or be refactored in some way later (like calculating a value).
Your test case verifies that you don't lose functionality.

On Mon, 5 Nov 2001, Kelso, JP Phil (5502) wrote:

> How about a class that can't possibly break?  Say a class with only setters
> and getters?
>
> > ----------
> > From:  Paolo Perrotta[SMTP:pperrotta@...]
> > Reply To:  junit@yahoogroups.com
> > Sent:  Monday, November 05, 2001 3:29 AM
> > To:  junit@yahoogroups.com
> > Subject:  Re: [junit] Who can tell me the scape of unit test of class.
> >
> > Can you submit an example of a class that you think should *not* be unit
> > tested?
> >
> >
> >  -----
> >
> >  I do not know if all the class should do unit test.
> >  Some class do not process the real action espc in the large
> > framework.
> >
> >
> > 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/>.
> >
>
> 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/
>
>
>

--
Eric Vought
Chief Technical Officer - QLUE Consulting, Inc.

evought@... toll-free: 888-771-3538  RTP area: 919-816-9901

#3177 From: "FrankSun" <franksun@...>
Date: Tue Nov 6, 2001 1:44 am
Subject: Re: Who can tell me the scape of unit test of class.
leafsun2001
Send Email Send Email
 
Thx all your response for my Question!
Our programe build on servlet tech, many object and param are form outside of the sigle class, like this is one of our class should be testing in unit phase.
First, I think I will construct all the object of the class needs and run the method, then see the result, this may be more like function :(
. I do not know is it right.
 
this is part of my class:
 
public HttpContext(ServletContext application, HttpServletRequest request, HttpServletResponse response)
 {
  _request    = request;
  _response   = response;
  _application = application;
  _session    = _request.getSession(false);
 
  Enumeration names = null;
  String name = null, value = null;
 
  if(isMultipartRequest())
  {
    // get data from MultipartRequest and put them into _requestData
   byte[] data= null;
   try
   {
    MultipartRequestTwo  multiReq = new MultipartRequestTwo(request,1024 * 1024 * 2);
    Enumeration byteNames = multiReq.getBinaryNames();
    while (byteNames.hasMoreElements())
    {
     name = (String)byteNames.nextElement();
     data = multiReq.getBinaryValues(name);
     _requestData.addField(name, new Field(name, Types.BLOB, data));
    }
    /**
     * get normal parameters
     */
    names = multiReq.getParameterNames();
    while(names.hasMoreElements())
    {
     name = (String)names.nextElement();
     receiveParam(name, multiReq);
     file://value = multiReq.getParameter(name);
     file://_requestData.addField(name, new Field(name, value));
    }
             }
    catch(Exception e)
             {
    _debug.log(e.getMessage());
    e.printStackTrace(_debug.getPrintStream());
             }
        }
  else
  {
      // get data from HttpServletRequest and put them into _requestData
   names = _request.getParameterNames();
   while(names.hasMoreElements())
   {
    name = (String)names.nextElement();
    receiveParam(name, _request);
    /*
    value = _request.getParameter(name);
    _requestData.addField(name, new Field(name, value));
    */
   }
  }
 
  if( _requestData.getString("NET_CONTENT") != null
                    && _requestData.getString("NET_CONTENT").equals("1")){
    setNetContent(true);
  }
                if( _requestData.getString("NET_PRINT") != null
                    && _requestData.getString("NET_PRINT").equals("1")){
    setNetPrint(true);
  }
  if(_requestData.getString("UO") != null
          && _requestData.getString("UO").equals("1"))
  {
   _uo = true;
  }
 }
 
 public void setNetContent(boolean isNet)
 {
  _isNetContent = true;
 }
}
----- Original Message -----
Sent: Monday, November 05, 2001 5:29 PM
Subject: Re: [junit] Who can tell me the scape of unit test of class.

Can you submit an example of a class that you think should *not* be unit tested?
 
-----
I do not know if all the class should do unit test.
Some class do not process the real action espc in the large framework.

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.

#3178 From: "FrankSun" <franksun@...>
Date: Tue Nov 6, 2001 1:49 am
Subject: Re: Who can tell me the scape of unit test of class.
leafsun2001
Send Email Send Email
 
My thought is your example is simple and it done a real (may be like)action is set or get some value. But in the real oo programe the class do more like this : accept may object and change value of other object.
If I will test this class, I will know all the object and construct all the object.
 
Sorry for my English, for it is not my native language.
Thx your answer!
----- Original Message -----
Sent: Tuesday, November 06, 2001 2:11 AM
Subject: RE: [junit] Who can tell me the scape of unit test of class.

Your test case verifies that you don't lose functionality.
Simple classes can break too. Especially if you use cut and paste to
create the setters/getters:

public class Point
{
      private int d_x;
      private int d_y;

      public int getX() {return d_x;}
      public void setX(int x) {d_x = x;}

      public int getY() {return d_y;}
      public void setY(int y) {d_x = y;}
} // class Point

There is also the possibility that the simple class will become more
complex or be refactored in some way later (like calculating a value).
Your test case verifies that you don't lose functionality.

On Mon, 5 Nov 2001, Kelso, JP Phil (5502) wrote:

> How about a class that can't possibly break?  Say a class with only setters
> and getters?
>
> > ----------
> > From:       Paolo Perrotta[SMTP:pperrotta@...]
> > Reply To:       junit@yahoogroups.com
> > Sent:       Monday, November 05, 2001 3:29 AM
> > To:       junit@yahoogroups.com
> > Subject:       Re: [junit] Who can tell me the scape of unit test of class.
> >
> > Can you submit an example of a class that you think should *not* be unit
> > tested?
> >
> >
> >       -----
> >
> >       I do not know if all the class should do unit test.
> >       Some class do not process the real action espc in the large
> > framework.
> >
> >
> > 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/>.
> >
>
> 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/
>
>
>

--
Eric Vought
Chief Technical Officer - QLUE Consulting, Inc.

evought@... toll-free: 888-771-3538  RTP area: 919-816-9901


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.

#3179 From: john_naylor@...
Date: Tue Nov 6, 2001 12:52 pm
Subject: testing private methods
jnaylor54321
Send Email Send Email
 
i have been assigned the task of pushing our development team toward
unit testing.  i have been working with junit for a few weeks now but
continue to struggle with one issue.  it seems to me there is tension
between unit testing and my preferred api.  for a given class i would
like to expose only a handful of methods, yet do not want to forfeit
testing my private methods.  my feeling is that i should be concerned
with continually testing those methods, and yet fail to see why i
should expose methods which are meaningless outside the "blackbox".

perhaps i am missing something obvious about good design.  in the
mean time i have set up a simple interface which classes i test
internally must implement.

public interface Testable
{
	 public static final boolean INTERNAL_MODE = true;

	 public void runInternalTests() throws Exception;
}

this allows me to run internal tests and handle assertions by calling
the static methods of Assert.  INTERNAL_MODE must be checked within
runInternalTests().  This allows internal testing to be turned off
for production builds.

any insight about this dilemna would be appreciated.

#3180 From: Carsten Zerbst <carsten.zerbst@...>
Date: Tue Nov 6, 2001 3:54 pm
Subject: Setup
carsten.zerbst@...
Send Email Send Email
 
Hello,

I'm pretty new to java, so please excuse a dumb question.

If got a class to test, my setup is something like

public class InformationDirectoryTest extends TestCase {
  SomeClass obj;

  public InformationDirectoryTest(String name) {
	 super(name);
  }
  public static Test suite()  {
	 return new TestSuite(InformationDirectoryTest.class);
  }
  public void setUp() {
     // create obj
  }
  public void tearDown() {
     // delete obj
  }

}

setUp and tear down are used for each testcase, but it would be enough
to run them once. There is an example in the FAQ but I couldn't find
out, how to get it running.

Thanks for any help, Carsten


--
Dipl. Ing. Carsten Zerbst         |   carsten.zerbst@...

#3181 From: "Strebel, Dr. Oliver" <Oliver.Strebel@...>
Date: Tue Nov 6, 2001 3:22 pm
Subject: AW: Setup
strebelel
Send Email Send Email
 
Hi Carsten!

Have a look at the faq-subdirectory in the JUnit documentation.
There you will find:

public static Test suite() {
   TestSuite suite= new TestSuite();
   ...add your tests and suites here...
   TestSetup wrapper= new TestSetup(suite) {
    public void setUp() {
     oneTimeSetUp();
    }
   };
   return wrapper;
}

Dr. Oliver Strebel

CC IT QU D
Windmuhlstr. 14
Raum 2.062
60301 Frankfurt

Tel.: 069/26316924
Fax: 069/26311838

E-Mail: Oliver.Strebel@...

The opinions herein are my own and do not necessarily reflect those of
Dresdner Bank AG.


-----Ursprungliche Nachricht-----
Von: Carsten Zerbst [mailto:carsten.zerbst@...]
Gesendet: Dienstag, 6. November 2001 16:54
An: junit@yahoogroups.com
Betreff: [junit] Setup


Hello,

I'm pretty new to java, so please excuse a dumb question.

If got a class to test, my setup is something like

public class InformationDirectoryTest extends TestCase {
  SomeClass obj;

  public InformationDirectoryTest(String name) {
	 super(name);
  }
  public static Test suite()  {
	 return new TestSuite(InformationDirectoryTest.class);
  }
  public void setUp() {
     // create obj
  }
  public void tearDown() {
     // delete obj
  }

}

setUp and tear down are used for each testcase, but it would be enough
to run them once. There is an example in the FAQ but I couldn't find
out, how to get it running.

Thanks for any help, Carsten


--
Dipl. Ing. Carsten Zerbst         |   carsten.zerbst@...



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/

#3182 From: Eric Vought <evought@...>
Date: Tue Nov 6, 2001 4:21 pm
Subject: Re: testing private methods
eric_vought
Send Email Send Email
 
Typically, the way you accomplish both objectives (hiding functionality
and exposing it for unit testing) is to use a Facade. You expose the
methods that you want available for testing within the package (package
private methods and/or classes). You create a public class (the Facade)
which exposes just the methods (for the package) you want. You hide the
actual classes you return from the Facade behind simple interfaces. Your
test classes are declared in the same package as your code and therefore
have access to the package protected functionality.

The second option you suggest runInternalTests(..) is also a good thing to
do. We call our equivalent interface InvariantsChecker and the method
checkInvariants(). We use this method to ensure that an object is in an
internally consistent state (e.g. that a stack's top index does not
exceed the capacity of the underlying array). You can then call this
method from within your test code:

void testPop() throws Exception
{
	 d_stack.push(d_item1);
	 d_stack.checkInvariants();

	 Object poppedItem = stack.pop();
	 d_stack.checkInvariants();

	 assertSame(item1, poppedItem);
} // testPop()

With a little care, you can have runInternalTests() or checkInvariants()
run recursively to run consistency checks on contained or referenced
components. The key is to make sure the checks terminate at some point.
We define a simple InvariantsTracker class which monitors the recursion
for us and ensures that it terminates. InvariantsTracker just keeps a list
of object instances that it has already seen. We pass a new
InvariantsTracker to the first checkInvariants(..) call which in turn
passes the same instance to recursive calls.

boolean checkInvariants(InvariantsTracker hitList)
{
	 if (hitList.alreadyHit(this)) return false;

	 Assert.invariant(d_top < d_size);

	 return true;
} // checkInvariants(..)

In a subclass, the form is slightly different, since the base class
performs the check:

boolean checkInvariants(InvariantsTracker hitList)
{
	 if (!(super.checkInvariants(hitList))) return false;

	 // ...

	 return true;
} // checkInvariants(..)

The test code then looks like this:

void testPop() throws Exception
{
	 d_stack.push(item1);
	 d_stack.checkInvariants(new InvariantsTracker());

	 // ...
} // testPop()

This ends up being a very simple and powerful technique. Having the unit
tests run the consistency checks in addition to checking external logic
allows you to catch many more errors with far fewer tests. You begin to
catch errors early on that don't normally show up until load or soak
testing and are much harder to diagnose then. Our code is available for
download if you are interested. There is also a package out
there called iContract which generates invariant checking code based on
special javadoc comments. iContract has the advantage that the invariants,
preconditions, and postconditions are clearly specified in your docs, but
its disadvantage is that it is a preprocessor.

On Tue, 6 Nov 2001 john_naylor@... wrote:

> i have been assigned the task of pushing our development team toward
> unit testing.  i have been working with junit for a few weeks now but
> continue to struggle with one issue.  it seems to me there is tension
> between unit testing and my preferred api.  for a given class i would
> like to expose only a handful of methods, yet do not want to forfeit
> testing my private methods.  my feeling is that i should be concerned
> with continually testing those methods, and yet fail to see why i
> should expose methods which are meaningless outside the "blackbox".
>
> perhaps i am missing something obvious about good design.  in the
> mean time i have set up a simple interface which classes i test
> internally must implement.
>
> public interface Testable
> {
>  public static final boolean INTERNAL_MODE = true;
>
>  public void runInternalTests() throws Exception;
> }
>
> this allows me to run internal tests and handle assertions by calling
> the static methods of Assert.  INTERNAL_MODE must be checked within
> runInternalTests().  This allows internal testing to be turned off
> for production builds.
>
> any insight about this dilemna would be appreciated.
>
>
>
>
> 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/
>
>
>

--
Eric Vought
Chief Technical Officer - QLUE Consulting, Inc.

evought@... toll-free: 888-771-3538  RTP area: 919-816-9901

#3183 From: "J. B. Rainsberger" <jbrains762@...>
Date: Tue Nov 6, 2001 4:38 pm
Subject: RE: Who can tell me the scape of unit test of class.
nails762
Send Email Send Email
 
Actually, it *can* break, depending on your naming conventions.

public class Broken {
     private String message;
     public Broken(String message) {
         message = message;
     }
     public String getMessage() { return message; }
     public void setMessage() { message = message; }
}

This class is broken, but this simple test would expose the bug.

public class BrokenTestCase extends TestCase {
     public BrokenTestCase(String name) { super(name); }
     public void testCreate() {
         Broken b = new Broken("Hello");
         assertEquals("Hello", b.getMessage());
         b.setMessage("Hello2");
         assertEquals("Hello2", b.getMessage());
     }
}

Now you will likely write, "I would never make that mistake." You might, if
you do a global search-and-replace on your code and the end result is the
code above. I leave it as an exercise to the reader to imagine how that
could happen. HINT: It happened to me. :)

My suggestions:

1. Use the immutable object idiom. (No setX() methods. If you need a new
value, make a new object.)
2. Write a simple test to ensure that what you pass to the constructor is
what the getX() methods answer.

Do this until you start writing perfect code all the time. :)

JBR.

----- Begin original message -----
How about a class that can't possibly break?  Say a class with only setters
and getters?



_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp

#3184 From: Eric Vought <evought@...>
Date: Tue Nov 6, 2001 5:27 pm
Subject: Re: RE: Who can tell me the scape of unit test of class.
eric_vought
Send Email Send Email
 
One of Brian Marick's key points in his book is that people don't make
complex mistakes. It's the simple things that are most likely to go wrong:
cut and paste errors, bad search and replace, off-by-one in a conditional
or loop, bas parenthesization, etc. If you look for the simple errors, you
catch them before they become complex problems.

On Tue, 6 Nov 2001, J. B. Rainsberger wrote:

> Actually, it *can* break, depending on your naming conventions.
>
> public class Broken {
>     private String message;
>     public Broken(String message) {
>         message = message;
>     }
>     public String getMessage() { return message; }
>     public void setMessage() { message = message; }
> }
>
> This class is broken, but this simple test would expose the bug.
>
> public class BrokenTestCase extends TestCase {
>     public BrokenTestCase(String name) { super(name); }
>     public void testCreate() {
>         Broken b = new Broken("Hello");
>         assertEquals("Hello", b.getMessage());
>         b.setMessage("Hello2");
>         assertEquals("Hello2", b.getMessage());
>     }
> }
>
> Now you will likely write, "I would never make that mistake." You might, if
> you do a global search-and-replace on your code and the end result is the
> code above. I leave it as an exercise to the reader to imagine how that
> could happen. HINT: It happened to me. :)
>
> My suggestions:
>
> 1. Use the immutable object idiom. (No setX() methods. If you need a new
> value, make a new object.)
> 2. Write a simple test to ensure that what you pass to the constructor is
> what the getX() methods answer.
>
> Do this until you start writing perfect code all the time. :)
>
> JBR.
>
> ----- Begin original message -----
> How about a class that can't possibly break?  Say a class with only setters
> and getters?
>
>
>
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
>
>
>
> 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/
>
>
>

--
Eric Vought
Chief Technical Officer - QLUE Consulting, Inc.

evought@... toll-free: 888-771-3538  RTP area: 919-816-9901

#3185 From: Shane Duan <sduan@...>
Date: Tue Nov 6, 2001 6:34 pm
Subject: Re: RE: Who can tell me the scape of unit test of class.
wolfdancer_dodo
Send Email Send Email
 
Actually, it doesn't matter much for me to argue the possibilities of
break.  After spending time on building mock objects, controllers and
setting up environment, I am just more than happy to spend one more
minute to test those setters and getters.  It really puts my mind on
ease knowing that I have a good test coverage instead of reminding
myself every time "You don't have test for the setters and getters
because they are too simple to test".

And yes, I did make mistake once on a setter and the test code caught
it.  (In case you wonder, I mistyped the name of the field variable and
the code insight found another one for me. :)  )

Shane

--
Disclaimer:  I join all the news groups out of my own interest.  All opinions
expressed here are my own and not necessarily those of my employer.

J. B. Rainsberger wrote:

>Actually, it *can* break, depending on your naming conventions.
>
>public class Broken {
>    private String message;
>    public Broken(String message) {
>        message = message;
>    }
>    public String getMessage() { return message; }
>    public void setMessage() { message = message; }
>}
>
>This class is broken, but this simple test would expose the bug.
>
>public class BrokenTestCase extends TestCase {
>    public BrokenTestCase(String name) { super(name); }
>    public void testCreate() {
>        Broken b = new Broken("Hello");
>        assertEquals("Hello", b.getMessage());
>        b.setMessage("Hello2");
>        assertEquals("Hello2", b.getMessage());
>    }
>}
>
>Now you will likely write, "I would never make that mistake." You might, if
>you do a global search-and-replace on your code and the end result is the
>code above. I leave it as an exercise to the reader to imagine how that
>could happen. HINT: It happened to me. :)
>
>My suggestions:
>
>1. Use the immutable object idiom. (No setX() methods. If you need a new
>value, make a new object.)
>2. Write a simple test to ensure that what you pass to the constructor is
>what the getX() methods answer.
>
>Do this until you start writing perfect code all the time. :)
>
>JBR.
>
>----- Begin original message -----
>How about a class that can't possibly break?  Say a class with only setters
>and getters?
>
>
>
>_________________________________________________________________
>Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp
>
>
>
>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/
>
>

Messages 3156 - 3185 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