I’m currently a Teacher’s Assistant for a class that uses Java. I’m trying to write a snippet of code that will test to make sure that student’s methods are correct, but often times the student won’t even implement the method, or they’ll call it something incorrect, which obviously will cause a Unresolved Compilation problem when my test code is run. Is there a way to catch this error during runtime, so that my test code can execute without having to play around with the code submitted by the student?
- edit: Just discovered that an Unresolved compilation problem is generated by the compiler before runtime. With this in mind, is there a way to do what I explained above?
- edit: Also, I don’t have any control over the way that assignments are structured, so I can’t introduce interfaces, or stubs, etc.
If I understand your question, you’re trying to validate both the interface that the student implements as well as the correctness of the implementation. The reflection API would allow to determine if a Class has implemented the correct API and if it has, invoke that API. Look at java.lang.Class, java.lang.Method, etc.