Let's say we have the following test code:
import org.jetbrains.annotations.NotNull;
import org.junit.Test;
public class NullTest {
@Test
public void testNull() {
doNothing(null);
}
private @NotNull String doNothing(@NotNull String value) {
return value;
}
}
The test will pass when running gradle test
directly or if IDEA delegates the action to gradle.
But it will fail with IllegalArgumentException: Argument for @NotNull parameter 'value' must not be null
exception if it runs using IDEA runner (not delegated to gradle).
The question is: how to fail the test running it with gradle?
The easiest solution I have found is to apply org.jetbrains.intellij plugin. Because among other things this plugin "patches compile tasks to instrument code with nullability assertions".
apply plugin: 'org.jetbrains.intellij'
intellij {
instrumentCode = true
downloadSources = false
}
Try adding the following to your dependencies. It worked for me.
compile 'org.jetbrains:annotations:13.0'
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