I have written a piece of framework that adds the possibility for type-safe invocations of its interface. Now, when writing the JUnit tests, I want to show that specific expressions that earlier led to runtime errors are checked by the compiler now.
// this does not compile, because nameProp is of type Property<String>
Integer name = interface.getProperty(nameProp);
Probably it'd be best to simply comment that code out and leave it like that. I was just wondering whether it'd be possible with some testing framework to write something like
assertCompilationError() {
Integer name = interface.getProperty(nameProp);
}
I explicitly do not want to fiddle around with invocations of javac with a custom classpath myself. If there is the possibility for a general solution that could be extracted to framework code (and donated to JUnit or TestNG) such a solution would be welcome as well.
You can't run JUnit until it compiles which is too late for this check.
You can't use a library to allow code which doesn't compile, to compile so you can check it doesn't compile.
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