jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vincent Massol" <vmas...@octo.com>
Subject Re: inner static classes
Date Wed, 31 Oct 2001 23:08:45 GMT

I am not religious on this point. I guess your way is fine. I can certainly
understand your concern for having the code and test code in the same place
+ addressing the testing of private methods.

Let's try to find some disadvantages (in no specific order, thus as it comes
to my mind) :
- inner classes are less well supported by IDEs (a lot have bugs)
- when you right click on your class in the IDE, and you click on execute,
is it going to execute the main from TestCase or the main from
ServletTestCase, or are the IDEs intelligent enough to ask you ? :)
- there might be a slight security hole in some cases if you leave the test
classes with your production code. Malicious users could try to call the
test class which, if it ontains errors, might set some state in memory which
would affect the behaviour of the class under test when accessed [that would
be true if your class under test has some static variables for example or
calling anything static]. ? So, it is difficult to package only the runtime
code without the test code.
- The class under test become bigger and more difficult to read.
- How I normally do it, is to have 2 directories, like one named "main" (or
core) and another named "tests" for example. Under each of these I would
have the same package hierarchy [which will let me unit test my protected
methods]. Also, with some ides, you have the option of seeing the sources
from different directories merged together in a single view and you'll be
able to see your XXXTest.java and XXX.java classes next to each other. Thus,
it is easy to find the test class related to any class.
- With Cactus, your test class is instanciated both on the client side and
on the server side. Thus, your class under test will also need to be
instanciated on the client side, complexifying a bit more all the jars that
you need to have on the client side classpath.

comments ? :)


----- Original Message -----
From: "Andrei" <avsomov@mail.ru>
To: <cactus-user@jakarta.apache.org>
Sent: Monday, October 29, 2001 1:12 PM
Subject: inner static classes

> Hi all,
> I have got a question concerning inner static classes.
> I have just started using two static inner test classes for one java
> It looks like this:
> public class MyClass {
>     ...
>     /** Test class.*/
>     public static class LocalTest extends junit.framework.TestCase {
>           // tests
>     }
>     /** Test class.*/
>     public static class ServerTest extends ServletTestCase  {
>           // tests
>     }
> }
> I test code that do not need to be executed on the server in
> the LocalTest class (usually small private methods).
> Advantages:
> 1. you do not think about the server while developing
> 2. test takes less time if executed alone.
>   (if you execute the whole suite for all classes you win nearly nothing)
> After developing it is possible to move all methods from LocalTest to
ServerTest and remove LocalTest. Or one can leave it as it is.
> The question is: is this way (using two inner test classes) error prone?
What are disadvantages?
> Many thanks,
> Andrei
> P.S. I could not find in the archive any messages about inner static test
> classes. Does anybody use them?
> --
> To unsubscribe, e-mail:
> For additional commands, e-mail:

To unsubscribe, e-mail:   <mailto:cactus-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:cactus-user-help@jakarta.apache.org>

View raw message