I'm trying to go through a large amout of classes with variable methods and have each method run with some generated input. It doesn't really matter what the result is, it only matters that there aren't any errors.
I have this code to find all methods and invoke them:
MyClassType theClass = new MyClassType(); // Fake class for example
Method[] methods = theClass.getClass().getMethods();
for (Method m : methods) {
try {
m.invoke(theClass, new Object[]{});
} catch (Exception ex) {
//Log error
}
}
This works fine for all methods that do not take any arguments, but fails for methods that do.
Is there any way I can programatically detect the type of arguments needed for each method and give it a test value? For example, all booleans are true
, all ints are 1
, all floats are 1.5f
, etc.
Look at the Method API, .... which to be honest really should have been the first place you should look before coming here actually. The getParametertypes()
method in the Method class will help. There are other useful methods present there including those that help with generic methods.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments