osdir.com
mailing list archive

Subject: Re: Re: design issue - msg#00197

List: java.junit.user

Date: Prev Next Index Thread: Prev Next Index

On 2002-06-26 at 15:31 Boris Garbuzov wrote:

>I found the third solution. Since my "single call
>code" uses no members of my test case, I placed former
>to static area of the latter as shown below. Had the
>code required members, it would have been possible to
>combine all test methods or even just overwrite run()
>method.
>
>---------------------------------
>
>public class AppTest
> extends TestCase
>{
>
> /*
> This is sure to be called once per process on class
>loading.
> */
> static
> {
> webclient.ClientMain.main(null);
> }
>
>==========================================

This is a design smell: static initializers make diagnosing problems
difficult, because they general require JVM shutdown and restart to
reproduce. Avoid them at all costs; use them only when absolutely no
other way could possibly work.

J. B. Rainsberger,
President, Diaspar Software Services
Let's write software that people understand.
http://www.diasparsoftware.com/
telephone: +1 416 791-8603
All correspondence (c) 2002 Diaspar Software Services.
If you want to use it, just ask; don't steal.




Was this page helpful?
Yes No
Thread at a glance:

Previous Message by Date: click to view message preview

Re: design issue

On 2002-06-26 at 15:01 Boris Garbuzov wrote: >Thanks, J.B., I will follow your practical >recommendation. But still there are 2 theoretical >questions: >1. How to implement TestListener in a TestCase? More >exactly, how to add it? >2. What is the difference between setUp() and >startTest()? Vladimir is probably a better person to answer these questions than I am, since he has worked more closely with the API from a developer's point of view. Vladimir? :) J. B. Rainsberger, President, Diaspar Software Services Let's write software that people understand. http://www.diasparsoftware.com/ telephone: +1 416 791-8603 All correspondence (c) 2002 Diaspar Software Services. If you want to use it, just ask; don't steal.

Next Message by Date: click to view message preview

Re: design issue

--- In junit@xxxx, Boris Garbuzov <boris_garbuzov@xxxx> wrote: > Thanks, J.B., I will follow your practical > recommendation. But still there are 2 theoretical > questions: > 1. How to implement TestListener in a TestCase? More > exactly, how to add it? > 2. What is the difference between setUp() and > startTest()? I'm far from an expert on the matter but... 1. As far as I know TestListeners are merely observers of tests. Usually in order to provide Views on test progress to the tester (of the person class -> end user subclass) so that they can informed of the results. I may be mistaken here but testers do not usually mess with TestListeners inside of a TestCase. In other words, they are interface elements. They follow (or are players in) the Observer Pattern as in the GOF book. http://c2.com/cgi/wiki?ObserverPattern http://c2.com/cgi/wiki?DesignPatternsBook The TestRunner classes are the observers in the standard jUnit framework. They indicate their interest of being notified of test progress/events by registering themselves with a TestResult. If you take a look at the source code inside TestRunner classes you can see how this is done. Those who extend or enhance the framework may add the listeners/observers in a different way but the idea is the same. 2. A tester puts in their code which does whatever is needed to set up a test's fixture in setUp(). Like opening a file, opening a database, or doing any initializations which may be common across all tests in a TestCase. startTest() is just for TestListeners it has nothing to do with a end user's writing of TestCase code. TestListeners are informed that a test has started through this interface. You can see this in the source code of TestResult. However, don't take my word for it as I can't even program in Java. Anthony Adachi

Previous Message by Thread: click to view message preview

Re: Re: design issue

I found the third solution. Since my "single call code" uses no members of my test case, I placed former to static area of the latter as shown below. Had the code required members, it would have been possible to combine all test methods or even just overwrite run() method. --------------------------------- public class AppTest extends TestCase { /* This is sure to be called once per process on class loading. */ static { webclient.ClientMain.main(null); } ========================================== > > You can wrap your whole suite in a TestSetup > subclass that calls > ClientMain.main(null); or you can figure out how to > write small-scale > tests. I write smaller scale tests whenever > possible, and if I think > about it hard enough, it's always possible. > > Kent > > __________________________________________________ Do You Yahoo!? Yahoo! - Official partner of 2002 FIFA World Cup http://fifaworldcup.yahoo.com

Next Message by Thread: click to view message preview

Re: design issue

> Can somebody suggest on some issue of JUnit API usage > or test case design? Sorry for a long appendix code. > The essence is that I want to start some application > once in VM session and run all my test methods > afterwards. I could not find sufficient place to put > my initial call > ClientMain.main (null); To be clear, you wish to execute some code once, then run all tests in a TestCase. If I understand you correctly, then please search through Google for the JUnit FAQ. The answer will be in there. Look for TestSetup. -- J. B. Rainsberger, President, Diaspar Software Services Let's write software that people understand. http://www.diasparsoftware.com/ telephone: +1 416 791-8603
Sign up for updates to this mailing list. email:
Loading Comments...
Home | News | Patents | Sitemap | FAQ | advertise

Advertising by