On Aug 20, 2013, at 8:25 AM, Mark Thomas wrote:

> On 20/08/2013 14:13, Nick Williams wrote:
>> I'm working on implementing bugzilla 55317. It's a pretty important
>> change (weaving) to a pretty import class (WebappClassLoader), so it
>> obviously needs some unit tests. However, I need some guidance:
>> 
>> 1) I've never gotten all the existing tests to pass on my machine.
>> Last time I ran them it took 45 minutes (holy crap) and about 1/3 of
>> them failed. This is obviously something wrong with my configuration
>> and not with Tomcat. I'd like to avoid running all tests for this
>> reason and only run the particular tests I'm working on. How would I
>> do this? Is this even possible with Ant?
> 
> ant test -Dtest.entry=org.apache.catalina.TestClassToExecute

Ahhh. Thanks! I somehow missed that when reading BUILDING.txt. Or, rather, more 
likely forgot, since I read it several months ago.

> svn co ...
> ant clean test
> 
> should work on Windows, Linux and OSX for all three connectors.
> 
> There are some tests that are 'fragile'. They need some time spent on
> them to figure out if they fail because the tests have a subtle timing
> bug (like the one I fixed this morning) or if the code does.
> 
> One or two failures wouldn't surprise me. 1/3 failing suggests a problem
> with the environment.

Agreed. The environment is Windows 7 Pro SP 1 64-bit running Java 8 beta 
64-bit. Could be a Java 8 issue. Could be a setup issue. Could be a number of 
other things. I'll try to troubleshoot it more once Java 8 is more stable. 
FWIW, only one or two tests failed on Java 7 64-bit on my Mac OS X Lion 
environment.

>> 2) I'm not sure exactly how to approach testing this particular
>> feature. It's obviously not completely straightforward. This is
>> weaving we're talking about, so somehow I have to load a class and
>> weave it to test that it's properly woven. Suggestions on where to
>> get started / what tools to use? As much as I hate it, part of me is
>> saying that functional testing is really the best course here, in
>> which case this is all moot.
> 
> Using weaving to add functionality that is easily tested to see if it is
> present?

Well, yea. I had figured that part out. :-) I just didn't articulate my 
question well enough.

The first step is obviously loading the class through the WACL through the unit 
test (so this has to be a class not already loaded). I assume I'll figure this 
part out reading through the existing WACL tests. But the key is *how* to use 
weaving in the context of the Tomcat unit tests. The way I see it I essentially 
have two options (though I may be overlooking something):

1) Manually manipulate the bytes. This takes great expertise and is ripe for 
failure. Not a big fan of the idea.
2) Introduce an additional test-time dependency on something like ASM. This is 
probably the safest route, but it introduces an additional test-time 
dependency. I don't know how amenable y'all are to that.

>> 3) I'm not even sure how to approach testing in Tomcat in general.
>> I've seen a lot of "unit tests" that look more like integration
>> tests, at least according to my training. Are there general
>> guidelines for writing "correct" unit tests in Tomcat, or is in
>> generally accepted as long as it passes?
> 
> Ideally, they should look like unit tests but a lot of the Tomcat code
> is not suited to that style of testing. There is nothing wrong with a
> little refactoring to aid testing but obviously there is a balance to
> strike.
> 
> Any test that a) provides value and b) passes is likely to be accepted.

Thanks. That helps.

Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to