You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by Tiago Espinha <ti...@espinhas.net> on 2011/06/04 10:57:52 UTC

Spawning a separate JVM inside a JUnit test

Hi all,

I'm currently converting tests/derbynet/DerbyNetAutoStart.java to a JUnit
test and this test does something peculiar. The first time around, it runs
as part of the harness and that's fine. However, after that run is done, it
spawns another JVM (check testExtantNetServer() ) and forces the test to be
ran again as part of the new JVM.

My question is: should we maintain this behavior in JUnit? And are there any
decorators that I don't know about to make a test run in a separate JVM?

I didn't want to have all that ugly code in a JUnit test where things are
more orderly and controlled, but is there really an alternative that I'm
missing?

Thanks,
Tiago

Re: Spawning a separate JVM inside a JUnit test

Posted by Bryan Pendleton <bp...@gmail.com>.
> I'm currently converting tests/derbynet/DerbyNetAutoStart.java to a JUnit test and this test does something peculiar. The first
> time around, it runs as part of the harness and that's fine. However, after that run is done, it spawns another JVM (check
> testExtantNetServer() ) and forces the test to be ran again as part of the new JVM.
>
> My question is: should we maintain this behavior in JUnit? And are there any decorators that I don't know about to make a test
> run in a separate JVM?
>
> I didn't want to have all that ugly code in a JUnit test where things are more orderly and controlled, but is there really an
> alternative that I'm missing?

This is an old test, and I agree that it's not very JUnit-like. It's much
more than a simple unit test in my opinion; it would be better termed
a "system" test or an "integration" test, as it operates the complete
client-server system in a multi-process fashion.

That said, it looks to me as though the testing code in testExtantNetServer
runs in the test process, not in the spawned Network Server subprocess, so
I think that testExtantNetServer could "just" be another JUnit test, albeit
one substantially more complicated than the typical test.

I'd say, do the minimum that you can to convert the test from an old-style
harness test to a JUnit test, and that by itself would be a successful
bit of work!

thanks,

bryan