JUnit for Memory footprint?

N

nibblix

Hello,
Does anyone know of any extensions to JUnit or any other testing
framework that would allow me to put checks on the memory footprint of
my java app? I'd like to ensure that major refactoring etc doesn't blow
out memory bounds.

thanks,
n
 
N

nibblix

I'm not looking for a tool to do memory analysis but more for a testing
framework where I can set memory bounds. For example, I should be able
to set a limit on the amount of java heap the module I'm testing uses.
If it crosses that threshold the test should fail.

thanks,
n
 
A

Andrew McDonagh

nibblix said:
I'm not looking for a tool to do memory analysis but more for a testing
framework where I can set memory bounds. For example, I should be able
to set a limit on the amount of java heap the module I'm testing uses.
If it crosses that threshold the test should fail.

thanks,
n

These types of tests are not Unit tests, they are more Acceptance tests.

As in...


The application can handle 100 concurrent clients using no more than
256mb of heap space.

To automate a test against this requirement, I'd used something like FIT
or FitNesse.

They use HTML tables to describe the Acceptance Test, and then actually
launch the application.

Take a look at

http://fitnesse.org/FitNesse.TwoMinuteExample
 
J

James McGill

To automate a test against this requirement, I'd used something like
FIT
or FitNesse.

Fit/Fitnesse looks so interesting, but it's SO hard to understand what
to do with it from their documentation. Maybe it makes more sense to
others, but I can't get my brain around it. I understand some *depth*
of it mind you, but that's not helpful until the *basics* are explained,
and the Fit/Fitnesse sites, pretty as they are, do a poor job of
explaining to a potential user, what the product is good for, and how to
begin using it.
 
A

Andrew McDonagh

Andrew said:
These types of tests are not Unit tests, they are more Acceptance tests.

As in...


The application can handle 100 concurrent clients using no more than
256mb of heap space.

To automate a test against this requirement, I'd used something like FIT
or FitNesse.

They use HTML tables to describe the Acceptance Test, and then actually
launch the application.

Take a look at

http://fitnesse.org/FitNesse.TwoMinuteExample

When writing the FitNesse testcase, you can specify how much heap the
JVM should use....


Tools like Fit & FitNesse are preferred for Acceptance Testing, as they
allow non-programmers to read & write testcases. They use the 'Domain
Specific Language' idea, which basically allows people who will use the
application, to know what the tests are doing, cause they are writtern
using the kind of words they would understand. Where as xUnit unit tests
are written in a programming language - which only programmers would
understand or be able to write new ones.

If you really want to use JUnit, then you can change the JVM parameters
of the JUnit session from within Eclipse's Run TestCase dialog. No doubt
other IDEs will allow the same.

Andrew
 
A

Andrew McDonagh

Andrew said:
These types of tests are not Unit tests, they are more Acceptance tests.

As in...


The application can handle 100 concurrent clients using no more than
256mb of heap space.

To automate a test against this requirement, I'd used something like FIT
or FitNesse.

They use HTML tables to describe the Acceptance Test, and then actually
launch the application.

Take a look at

http://fitnesse.org/FitNesse.TwoMinuteExample


Link to FIT

http://fit.c2.com/wiki.cgi?IntroductionToFit


Fit is the actual Framework for Integrated Tests, FitNesse is a simple
Wiki around Fit, that allows remote users to browser to the FIT server
and Run, create, edit, delete tests - amongst other cool things.

Andrew
 
N

nibblix

Consider the case where I have foo( ) having a peak heap usage of 150M.
I'd like to write a unit test case that ensures that future
refactoring/changes of foo() does not cause the heap to grow beyond
150M.

One way would be to set the Xmx to 150M but I'm looking for a way to do
this without causing the JVM to error out.

thanks,
n
 
A

Andrew McDonagh

nibblix said:
Consider the case where I have foo( ) having a peak heap usage of 150M.
I'd like to write a unit test case that ensures that future
refactoring/changes of foo() does not cause the heap to grow beyond
150M.

One way would be to set the Xmx to 150M but I'm looking for a way to do
this without causing the JVM to error out.

thanks,
n

There's no Unit Test reliable means of doing this.

The best you can do is use the Runtime memory methods to check that
current usage after running foo() is less than 150M. The problem with
this is that other factors may make the test pass or fail intermittently
- eg GC previous testcases mount up memory usage before GC can reclaimm etc.

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/Runtime.html

e.g.

public void testMemoryConsumptionIsBelowMaximumHeapSize() {

Runtime rt = Runtime.getRuntime();

assertTrue("Sanity test - starting memory is already beyond heap size
target", rt.totalMemory() < 150);

ClassUnderTest.foo();

assertTrue("Heap size target exceeded", rt.totalMemory() < 150);
}

It would also be a stress test of Foo() which is only being tested
within the single threaded nature of JUnit. It wouldn't be testing
Foo() in the nature of how it would be used in the application, where
other processing would be happening which might take memory consumption
over the limit.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,017
Latest member
GreenAcreCBDGummiesReview

Latest Threads

Top