1

Hello all :) In the JVM debug mode you can inspect the objects that are present when you run your code.

This means one can create a utility that can generate a dump of those objects as ready to use mocks (or close enough, hopefully). Those mocks would span the entire scope of the program run, and this would help greatly in building an extensive test coverage.

Because lazy is good, I was wondering if such a utility is currently available.

Best regards

Community
  • 1
  • 1
BenoitParis
  • 3,166
  • 4
  • 29
  • 56
  • Are you looking for something like JMock or Mockito? Also do you have any code you can post that may help in answering the question? – The Cat Apr 17 '13 at 14:25
  • Any testing framework would do. Can JMock or Mockito generate mock objects by observing code run? – BenoitParis Apr 17 '13 at 14:31
  • JMock or Mockito help with unit testing, I am not sure this is what you are after though. – The Cat Apr 17 '13 at 14:34

1 Answers1

1

I don't know of a way to do this from a memory/heap dump or from debug mode but...

If you want to serialize arbitrary java objects to and from files for use in tests then you can use XStream to do so. You could then use them in your unit tests with ease.

You can also use standard Java serialization if your objects are all serializable.

To collect the data in the first place you can create an aspect using AspectJ or Spring-AOP or similar. I've done something similar in the past and it worked really well.

One word of caution though: If you are doing this then any refactoring of your objects require refactoring of the test data. This is easier with XStream as it's XML files you are dealing with.

James
  • 1,541
  • 12
  • 25