Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Catch Unresolved Compilation Errors in Java

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.
like image 986
Michael Hogenson Avatar asked Oct 25 '11 18:10

Michael Hogenson


People also ask

How can compilation error be resolved in Java?

If the brackets don't all match up, the result is a compile time error. The fix to this compile error is to add a leading round bracket after the println to make the error go away: int x = 10; System.

What is compilation error with example?

Compiler errors are due to inaccuracies in code, where the compiler throws an error to alert you to something which will not compile, and therefore cannot be run. An example of a compiler error would be: int = "this is not an int"; Hope that helps.

What is compilation error?

Compilation error refers to a state when a compiler fails to compile a piece of computer program source code, either due to errors in the code, or, more unusually, due to errors in the compiler itself. A compilation error message often helps programmers debugging the source code.


1 Answers

If I were a TA, I would write some unit tests and tell the students to make the test pass. Get them into testing early on.

If the code doesn't compile, it doesn't make sense to detect that at runtime. You can't run if it won't compile.

like image 80
hvgotcodes Avatar answered Sep 30 '22 05:09

hvgotcodes