You can use a TestRule, that adds the generated code to the output of failing tests. I suggest to extend TestWatcher.
public class GeneratedCodeLogger extends TestWatcher {
private Logger log;
public GeneratedCodeLogger(Logger log) {
this.log = log;
}
@Override
protected void failed(Description d) {
System.out.println(log.toString());
}
}
Your test has to use this rule and log the generated code to the logger.