Is it possible to use java.lang.instrument.Instrumentation in JUnit tests? -
Is it possible to use java.lang.instrument.Instrumentation in JUnit tests? I am using Moncaroon to simulate a servlet and want to measure the size of the items stored in the session.
Yes, this is possible, but not very straightforward.
The problem with using java.lang.instrument.Instrumentation is that you will always need to use a JVM agent, a good introduction to JVM agents is available.
However, because your unit test is also run in a JVM, you can specify the agent as a JVM logic.
A memory reporting is available on JVM agents that you want to pack, and are ready for packaging. You can make it with Maven or Ant, to use it, you make it and then when you start the Unit Test or Unit Test suite, pass the following as a jvm argument:
< Pre> -zavgent: & lt; Path to & gt; Within the unit tests, you can instantiate the memory meter and use it: memory meter = new memory meter ()
; Meter.measure (object); Meter.measureDeep (object); Meter.countChildren (object);
Comments
Post a Comment