I am currently testing a part of my application (that we will assume is a class named X) that takes as parameter a reflection java Method, and will print some java code based on it (that is, it is a code generator). For instance, when passing String.toString() to X, the rendered string output would be:
public static java.lang.String toString(String thisObj, boolean isMonitoring) {
String thisObjOld = (String)thisObj.clone(thisObj, false);
if (isMonitoring) {
toStringPre(thisObj);
}
java.lang.String result = thisObj.toString_Original();
if (isMonitoring) {
toStringPost(thisObj, thisObjOld, result);
}
return result
}
Now, I am wondering how to test this output. I'd like to test different things (individually).
I know the perfect thing to do would be to make assertions against an abstract representation, just before the printing, instead of the final text. But unfortunately, it seems that would be just too much work to set up.
Examples of things I'm looking to test are:
java.lang.String);toString), as well as its parameters `(String thisObj, boolean isMonitoring).How to better approach this? Using regular expressions? Using String.split()?
What about compiling the generate code - Test that the code is syntactic correct.
Then use Reflection to check the Name, Parameter and Return type.
Then run it in a Mocked environment to check that it does what it should do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With