I would like to display a warning in a JUnit
test. I don't want the test to fail because of that warning but I would like to know that the warning occurs. Obviously, I can use System.err.print
or something similar. Now I wonder what is the right way to do it
I have also thought that this would useful at times, but this can't be done. JUnit insists on a right and wrong answer and so only has "success", "fail", and "error". Error being when something breaks in the code while running the test. I would refactor and consider if you really need a warning (or log like the previous answer suggests, although I think this warning would soon get lost),
use logger with console appender for it
final Logger logger = LoggerFactory.getLogger(LoggingTest.class);
@Test
public void test() {
logger.warn("message");
}
PS. Example using slf4j logger.
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