Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Runner for forked Junit tests(Avoiding memory issues with Junit runner from Eclipse)
Runner for forked Junit tests [message #754592] Thu, 03 November 2011 12:57 Go to next message
Chris S is currently offline Chris SFriend
Messages: 20
Registered: November 2011
Junior Member
Hi,

we're running into memory problems inside Eclipse when running our Junit test suite and it is because of the standard Junit runner keeping references from old tests (as documented in a number of places on the net). We don't want to spend time null:ing out all fields in our test cases, since the same thing works with an ant task with the "fork=yes" option. I can run the the ant task we have, but then I only get the output in the console and not the graphical output from the regular junit runner, so that isn't good enough for our users. Also, increasing the memory for the test configuration is just a temporary solution since in that case, it will just keep growing until it becomes too large next time.

So what I'd like is:
a) an option to the standard JUnit runner to make it fork the way that ant does junit, so we don't have to modify our test classes
b) get a better integration for running the ant task so that is uses the junit "GUI output" (and that it updates it during runtime, the pure import of the XML afterwards doesn't solve it for us).

Is there any existing solution for either of the above?
If not, how difficult would it be to modify the core JUnit runner to use ant or to fork? Or would it be as easy to write new plug-in from scratch?

Note: Using Junit4 and Eclipse 3.7.

BR,
Chris
Re: Runner for forked Junit tests [message #755145 is a reply to message #754592] Mon, 07 November 2011 14:12 Go to previous messageGo to next message
Markus KellerFriend
Messages: 294
Registered: July 2009
Senior Member
a) The Eclipse "JUnit" and "JUnit Plug-in Test" launch configurations always run the tests in a separate VM, so you already get the "fork" behavior. The "JUnit" launch config should not use more memory than the Ant task, but the "JUnit Plug-in Test" needs more, since it runs a full Eclipse application in the target VM. For that one, you may have to increase the allocated memory a bit.

b) I don't see what advantages it would have to add Ant as an intermediate layer. It could never do more than junit.core, which already speaks to JUnit directly.
Re: Runner for forked Junit tests [message #755323 is a reply to message #755145] Tue, 08 November 2011 07:18 Go to previous messageGo to next message
Chris S is currently offline Chris SFriend
Messages: 20
Registered: November 2011
Junior Member
Hi Markus,

thanks for the reply.

According to what I can see, the JUnit runner in Eclipse keeps references to the test classes that is has previously run and therefore leaves a lot of memory around that ant doesn't. Therefore, I don't get the "fork" behavior that I would like.
There seems to be others that have noticed this, see for example this (somewhat older) page: www.symphonious.net/2006/09/19/junit-memory-usage-in-eclipse/ (I have foudn the same "complaints" on other sites/forums as well). I've run our tests through a profiler and I see the same kind of problem. I don't want to require our developers having to null out all the fields to get the same kind of performance we get from ant. Please correct me if I have missed something obvious here

I think there are multiple advantages of having ant run the tests "integrated" into the eclipse runner. For example, in ant, it is relatively easy to set up a target for running the tests in multiple parallel threads to speed up the execution (yes, I know, our tests are far too slow to be proper unit tests....), which I haven't found a way to do from eclipse.

BR,
Chris
Re: Runner for forked Junit tests [message #755828 is a reply to message #755323] Wed, 09 November 2011 17:39 Go to previous messageGo to next message
Markus KellerFriend
Messages: 294
Registered: July 2009
Senior Member
How exactly are you running your tests? Do you have a TestSuite that contains all tests, or do you use "Run all tests in ..." in Eclipse and a <batchtest> in Ant?

Or do you compare apples with pears and run all tests in one VM in Eclipse but have separate <junit> tasks in Ant?

If you have reproducible steps (e.g. dummy tests that allocate big arrays to waste space), then please file a bug for JDT UI.
Re: Runner for forked Junit tests [message #756054 is a reply to message #755828] Thu, 10 November 2011 16:37 Go to previous messageGo to next message
Chris S is currently offline Chris SFriend
Messages: 20
Registered: November 2011
Junior Member
Hi Markus,

in Eclipse, we usually just right-click on the test directory and "Run as JUnit test". And when I added debugging prints of memory usage to our tests, and it definitely saves memory form all fields in the test classes as it increases for every test it has run. So does this mean I'm running in just one JVM? If so, how do I get around it from inside Eclipse?

In ant, our target is something like this (removed irrelevant text):
<target name="runtests"
<junit printsummary="yes" haltonfailure="no" timeout="60000">
<batchtest fork="yes" todir="${build.test}">
<fileset refid="arg.testclasses"/>
</batchtest>
</junit>
</target>

I don't have reproducible tests right now, but I could try to do some next week if it isn't something wrong with the above.
Re: Runner for forked Junit tests [message #756790 is a reply to message #756054] Tue, 15 November 2011 06:03 Go to previous messageGo to next message
Deepak Azad is currently offline Deepak AzadFriend
Messages: 543
Registered: July 2009
Senior Member
On 11/10/2011 10:07 PM, Chris wrote:
> Hi Markus,
>
> in Eclipse, we usually just right-click on the test directory and "Run
> as JUnit test". And when I added debugging prints of memory usage to our
> tests, and it definitely saves memory form all fields in the test
> classes as it increases for every test it has run. So does this mean I'm
> running in just one JVM? If so, how do I get around it from inside Eclipse?

I think it does uses JUnit does use a single VM. Also I do not see a way
around it.

> In ant, our target is something like this (removed irrelevant text):
> <target name="runtests"
> <junit printsummary="yes" haltonfailure="no" timeout="60000">
> <batchtest fork="yes" todir="${build.test}">
> <fileset refid="arg.testclasses"/>
> </batchtest>
> </junit>
> </target>
>
> I don't have reproducible tests right now, but I could try to do some
> next week if it isn't something wrong with the above.

Related questions on Stackoverflow

-
http://stackoverflow.com/questions/2890259/running-each-junit-test-in-a-separate-jvm-in-eclipse
-
http://stackoverflow.com/questions/681133/why-does-heap-space-run-out-only-when-running-junit-tests

--
Deepak Azad
http://wiki.eclipse.org/JDT/FAQ
Re: Runner for forked Junit tests [message #756910 is a reply to message #756790] Tue, 15 November 2011 13:53 Go to previous messageGo to next message
Markus KellerFriend
Messages: 294
Registered: July 2009
Senior Member
If Ant's <batchtest fork="yes"> starts separate VMs for each test, then that would explain the difference.

Unfortunately, there's no easy way to get that behavior in Eclipse. The whole implementation of the UI is currently based on the assumption that only one separate VM is started and test results only come from that VM. The tricky part is the setup of a direct communication channel between the host and the target VMs, the correct synchronization between results coming from different VMs, and the proper termination of all those target VMs.

https://bugs.eclipse.org/298061 asked for something similar, but I don't think we will have the resources to work on this.
https://bugs.eclipse.org/39900 could also help a bit if you can separate your tests into manageable chunks that can be run together in one VM.
Another approach could be to implement a custom JUnitResultFormatter that could talk to the Eclipse JUnit view, but that's also quite some work if multiple formatters should talk to the same UI in parallel.

For running tests in parallel in one VM, JUnit 3 has the ActiveTestSuite. Maybe there's something similar in JUnit 4 (didn't see it on a quick look, though).

Markus
Re: Runner for forked Junit tests [message #757260 is a reply to message #756910] Thu, 17 November 2011 11:47 Go to previous message
Chris S is currently offline Chris SFriend
Messages: 20
Registered: November 2011
Junior Member
Hi again Markus,

I think we misunderstood each other a bit in the beginning, but now we're on the same page.

We've started to work on a modification of the runner that will allow JUnit in multiple JVMs from Eclipse and the initial prototyping seems promising. Our main issue with the current Eclipse runner is that we have large static objects that are kept around when using a single JVM. So if we can fix the runner, that is easier than having to make "SoftReference-caches" out of all static objects.

Thanks for the help.

/Chris
Previous Topic:SOS:Latest Eclipse can not use Jadclpse
Next Topic:Can not debug?
Goto Forum:
  


Current Time: Sat Apr 20 01:56:14 GMT 2024

Powered by FUDForum. Page generated in 0.03636 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top