You have code, you have a running system - and you have no tests. This is where Testrecorder jumps in. The most relevant tests of a system are those, that resemble the workflow of the users of the system. Testrecorder records every user interaction a selected method is involved in and generates executable JUnit-Tests for this interaction.

testrecorder is as capture-replay test generator. In contrast to most other capture-replay test generators testrecorder does not generate gui/web integration tests but pure Java unit tests.

Basic Usage

1. Annotate the method to record

Annotate the method to record with @Recorded. For example you want to record this simple example

2. Configure the test serialization

Create a directory agentconfig (either on your classpath or in the directory you run from). This directory should contain at least two files:

net.amygdalum.testrecorder.profile.SerializationProfile containing a single line:

fizzbuzz.SerializationProfile

net.amygdalum.testrecorder.SnapshotConsumer containing a single line:

fizzbuzz.TestGenerator

These files refer two the configuration classes. A SerializationProfile configures which classes/methods/fields should be analyzed, included or excluded from recording. A SnapshotConsumer is notified if some recorded ContextSnapshot is available. Typically we want to generate Tests from the snapshot, so we plug in a configured instance of ScheduledTestGenerator.

Benefits

Use the generated tests as characterization tests for test regression. Many refactoring will directly adjust the test, few will need some manual corrections and none will force you to dig in xml (or java serialization code) to correct the data of the test.

The generated test can also give you insights about what is changed in the tested scenario - involving not only primitive arguments and results, but also side effects on arguments, global variables and exceptions.

And if you think testrecording is cool, but byte code instrumetation is not: the api of testrecorder is open. You may generate setup code (the code that generates a given object) and matcher code (the code that validates a given object) as part of your debugging (or runtime system).