How to write something in the help log with JUnit 4

Is it possible to write something from inside the test in surefire-reports / MyClass.txt? Any kind of registrar, etc.? TestNG has a reporter:

Reporter.log("Something here"); 

and the message appears in the test method in the report. Is there something similar in JUnit

+4
source share
1 answer

I was fortunate enough to use log4j in junit with this setup when working in Eclipse or through Hudson. This may not work with the combination of tests / runners / IDEs you use, as this does not work in all cases for me. You may need to configure forkMode. You will also have to create hard codes.

 <plugin> <artifactId>maven-surefire-plugin</artifactId> <configuration> <forkMode>never</forkMode> <systemProperties> <property> <name>log4j.configuration</name> <value>file:src/test/resources/log4j.xml</value> </property> </systemProperties> </configuration> </plugin> 

Another might be to use redirectTestOutputToFile to output stdout to the surefire report file. They haven’t used it, so I don’t know if this will work for you either.

+2
source

Source: https://habr.com/ru/post/1311503/


All Articles