Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning in JUnit tests

Tags:

java

junit

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

like image 909
Michael Avatar asked Dec 25 '12 08:12

Michael


2 Answers

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),

like image 174
RNJ Avatar answered Oct 27 '22 21:10

RNJ


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.

like image 42
Ilya Avatar answered Oct 27 '22 22:10

Ilya