Testing / JUnit6 Interview Questions
What is TestReporter in JUnit 6 and how do you use it?
TestReporter lets test methods publish key-value entries to the test execution report. Unlike System.out.println, reported values are attached to the test result and appear in IDE test reports and XML output -- they are not just lost in console noise.
import org.junit.jupiter.api.TestReporter; class TestReporterDemo { @Test void reportingDemo(TestReporter reporter) { // Publish a single key-value entry reporter.publishEntry("user-id", "U-12345"); reporter.publishEntry("status", "active"); // Publish a map of entries in one call Map<String, String> values = Map.of( "order-id", "O-99", "total", "149.99", "currency", "GBP" ); reporter.publishEntry(values); // Assertions still run after publishing entries assertTrue(true); } @Test void reportWithMessage(TestReporter reporter) { // Single-argument form: just a message string reporter.publishEntry("Processing payment for order O-42"); } } // TestReporter vs System.out: // // System.out.println: // - Goes to process stdout // - Not associated with any specific test in the report // - Lost in CI log noise // // TestReporter.publishEntry: // - Attached to the specific test result // - Appears in IDE test runner output alongside the test // - Included in XML/HTML test reports // - Visible when you click on a specific test result in the IDE
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
