Record method calls including parameters such that they can be executed after program has executed
I am creating an automated test framework. At present in order to best find any issues I have introduced randomness into the tests, such that a test will generate random data and try multiple paths. However this has lead to a problem, I am no longer able to easily re-execute failed tests.
In order to proceed I need to implement a way to store the actions 开发者_Python百科of the test, including their parameters. With the way I have implemented the framework all of the "work" is handled by one class, thus if I was able to record the methods invoked with parameters in this class then I would have a full record of actions executed in the script.
From this list of methods though I need an easy way to re-execute these method calls, preferably with as little manual work as possible.
Sorry if this has been asked before but I wasn't able to find anything to help.
While it may be possible to record and reproduce the actions by some complex reflection or aspect-oriented programming, it's probably easier to just make the process repeatable by dealing with the randomness a bit differently.
Precisely how the current version of java.util.Random
determines the seed if it's not specified, I'm not sure. In 1.4.2, it was documented as being
public Random() { this(System.currentTimeMillis()); }
But if instead of letting it default to something based on current time and out of your control, you explicitly set the seed to something known (possibly System.currentTimeMillis()
), and record the seed that was used, then you can easily replay with the same seed and get the same sequence of "random" numbers.
精彩评论