How to use VerboseReporter class of org.testng.reporters package

Best Testng code snippet using org.testng.reporters.VerboseReporter

Source:VerboseReporter.java Github

copy

Full Screen

...37 * 38 * THIS IS AN EXACT COPY OF THE CLASS IN org.testng.reporters39 * EXCEPT FOR THIS COMMENT AND log(String) CHANGED TO BE PROTECTED40 */41public class VerboseReporter extends TestListenerAdapter {42 /**43 * Default prefix for messages printed out by this reporter44 *45 */46 public static final String LISTENER_PREFIX = "[VerboseTestNG] ";47 private String suiteName;48 private final String prefix;49 private enum Status {50 SUCCESS(ITestResult.SUCCESS), FAILURE(ITestResult.FAILURE), SKIP(ITestResult.SKIP),51 SUCCESS_PERCENTAGE_FAILURE(ITestResult.SUCCESS_PERCENTAGE_FAILURE), STARTED(ITestResult.STARTED);52 private final int code;53 private Status(int i) {54 code = i;55 }56 57 @SuppressWarnings("unused")58 public int getCode() {59 return code;60 }61 }62 /**63 * Default constructor64 */65 public VerboseReporter() {66 this(LISTENER_PREFIX);67 }68 /**69 * Create VerboseReporter with custom prefix70 *71 * @param prefix prefix for messages printed out by this reporter72 */73 public VerboseReporter(String prefix) {74 this.prefix = prefix;75 }76 @Override77 public void beforeConfiguration(ITestResult tr) {78 super.beforeConfiguration(tr);79 logTestResult(Status.STARTED, tr, true);80 }81 @Override82 public void onConfigurationFailure(ITestResult tr) {83 super.onConfigurationFailure(tr);84 logTestResult(Status.FAILURE, tr, true);85 }86 @Override87 public void onConfigurationSkip(ITestResult tr) {88 super.onConfigurationSkip(tr);89 logTestResult(Status.SKIP, tr, true);90 }91 @Override92 public void onConfigurationSuccess(ITestResult tr) {93 super.onConfigurationSuccess(tr);94 logTestResult(Status.SUCCESS, tr, true);95 }96 @Override97 public void onTestStart(ITestResult tr) {98 logTestResult(Status.STARTED, tr, false);99 }100 @Override101 public void onTestFailure(ITestResult tr) {102 super.onTestFailure(tr);103 logTestResult(Status.FAILURE, tr, false);104 }105 @Override106 public void onTestFailedButWithinSuccessPercentage(ITestResult tr) {107 super.onTestFailedButWithinSuccessPercentage(tr);108 logTestResult(Status.SUCCESS_PERCENTAGE_FAILURE, tr, false);109 }110 @Override111 public void onTestSkipped(ITestResult tr) {112 super.onTestSkipped(tr);113 logTestResult(Status.SKIP, tr, false);114 }115 @Override116 public void onTestSuccess(ITestResult tr) {117 super.onTestSuccess(tr);118 logTestResult(Status.SUCCESS, tr, false);119 }120 @Override121 public void onStart(ITestContext ctx) {122 suiteName = ctx.getName();//ctx.getSuite().getXmlSuite().getFileName();123 log("RUNNING: Suite: \"" + suiteName + "\" containing \"" + ctx.getAllTestMethods().length + "\" Tests (config: " + ctx.getSuite().getXmlSuite().getFileName() + ")");124 }125 @Override126 public void onFinish(ITestContext context) {127 logResults();128 suiteName = null;129 }130 private ITestNGMethod[] resultsToMethods(List<ITestResult> results) {131 ITestNGMethod[] result = new ITestNGMethod[results.size()];132 int i = 0;133 for (ITestResult tr : results) {134 result[i++] = tr.getMethod();135 }136 return result;137 }138 /**139 * Print out test summary140 */141 private void logResults() {142 //143 // Log test summary144 //145 ITestNGMethod[] ft = resultsToMethods(getFailedTests());146 StringBuilder sb = new StringBuilder("\n===============================================\n");147 sb.append(" ").append(suiteName).append("\n");148 sb.append(" Tests run: ").append(getAllTestMethods().length);149 sb.append(", Failures: ").append(ft.length);150 sb.append(", Skips: ").append(resultsToMethods(getSkippedTests()).length);151 int confFailures = getConfigurationFailures().size();152 int confSkips = getConfigurationSkips().size();153 if (confFailures > 0 || confSkips > 0) {154 sb.append("\n").append(" Configuration Failures: ").append(confFailures);155 sb.append(", Skips: ").append(confSkips);156 }157 sb.append("\n===============================================");158 log(sb.toString());159 }160 /**161 * Log meaningful message for passed in arguments.162 * Message itself is of form:163 * $status: "$suiteName" - $methodDeclaration ($actualArguments) finished in $x ms ($run of $totalRuns)164 *165 * @param st status of passed in itr166 * @param itr test result to be described167 * @param isConfMethod is itr describing configuration method168 */169 private void logTestResult(Status st, ITestResult itr, boolean isConfMethod) {170 StringBuilder sb = new StringBuilder();171 String stackTrace = "";172 switch (st) {173 case STARTED:174 sb.append("INVOKING");175 break;176 case SKIP:177 sb.append("SKIPPED");178 stackTrace = itr.getThrowable() != null179 ? Utils.shortStackTrace(itr.getThrowable(), false) : "";180 break;181 case FAILURE:182 sb.append("FAILED");183 stackTrace = itr.getThrowable() != null184 ? Utils.shortStackTrace(itr.getThrowable(), false) : "";185 break;186 case SUCCESS:187 sb.append("PASSED");188 break;189 case SUCCESS_PERCENTAGE_FAILURE:190 sb.append("PASSED with failures");191 break;192 default:193 //not happen194 throw new RuntimeException("Unsupported test status:" + itr.getStatus());195 }196 if (isConfMethod) {197 sb.append(" CONFIGURATION: ");198 } else {199 sb.append(": ");200 }201 ITestNGMethod tm = itr.getMethod();202 int identLevel = sb.length();203 sb.append(getMethodDeclaration(tm));204 Object[] params = itr.getParameters();205 Class<?>[] paramTypes = tm.getConstructorOrMethod().getParameterTypes();206 if (null != params && params.length > 0) {207 // The error might be a data provider parameter mismatch, so make208 // a special case here209 if (params.length != paramTypes.length) {210 sb.append("Wrong number of arguments were passed by the Data Provider: found ");211 sb.append(params.length);212 sb.append(" but expected ");213 sb.append(paramTypes.length);214 } else {215 sb.append("(value(s): ");216 for (int i = 0; i < params.length; i++) {217 if (i > 0) {218 sb.append(", ");219 }220 sb.append(Utils.toString(params[i], paramTypes[i]));221 }222 sb.append(")");223 }224 }225 if (Status.STARTED != st) {226 sb.append(" finished in ");227 sb.append(itr.getEndMillis() - itr.getStartMillis());228 sb.append(" ms");229 if (!Utils.isStringEmpty(tm.getDescription())) {230 sb.append("\n");231 for (int i = 0; i < identLevel; i++) {232 sb.append(" ");233 }234 sb.append(tm.getDescription());235 }236 if (tm.getInvocationCount() > 1) {237 sb.append(" (");238 sb.append(tm.getCurrentInvocationCount());239 sb.append(" of ");240 sb.append(tm.getInvocationCount());241 sb.append(")");242 }243 if (!Utils.isStringEmpty(stackTrace)) {244 sb.append("\n").append(stackTrace.substring(0, stackTrace.lastIndexOf(System.getProperty("line.separator"))));245 }246 } else {247 if (!isConfMethod && tm.getInvocationCount() > 1) {248 sb.append(" success: ");249 sb.append(tm.getSuccessPercentage());250 sb.append("%");251 }252 }253 log(sb.toString());254 }255 protected void log(String message) {256 //prefix all output lines257 System.out.println(message.replaceAll("(?m)^", prefix));258 }259 /**260 *261 * @param method method to be described262 * @return FQN of a class + method declaration for a method passed in263 * ie. test.triangle.CheckCount.testCheckCount(java.lang.String)264 */265 private String getMethodDeclaration(ITestNGMethod method) {266 //see Utils.detailedMethodName267 //perhaps should rather adopt the original method instead268 ConstructorOrMethod m = method.getConstructorOrMethod();269 StringBuilder buf = new StringBuilder();270 buf.append("\"");271 if (suiteName != null) {272 buf.append(suiteName);273 } else {274 buf.append("UNKNOWN");275 }276 buf.append("\"");277 buf.append(" - ");278 if (method.isBeforeSuiteConfiguration()) {279 buf.append("@BeforeSuite ");280 } else if (method.isBeforeTestConfiguration()) {281 buf.append("@BeforeTest ");282 } else if (method.isBeforeClassConfiguration()) {283 buf.append("@BeforeClass ");284 } else if (method.isBeforeGroupsConfiguration()) {285 buf.append("@BeforeGroups ");286 } else if (method.isBeforeMethodConfiguration()) {287 buf.append("@BeforeMethod ");288 } else if (method.isAfterMethodConfiguration()) {289 buf.append("@AfterMethod ");290 } else if (method.isAfterGroupsConfiguration()) {291 buf.append("@AfterGroups ");292 } else if (method.isAfterClassConfiguration()) {293 buf.append("@AfterClass ");294 } else if (method.isAfterTestConfiguration()) {295 buf.append("@AfterTest ");296 } else if (method.isAfterSuiteConfiguration()) {297 buf.append("@AfterSuite ");298 }299 buf.append(m.getDeclaringClass().getName());300 buf.append(".");301 buf.append(m.getName());302 buf.append("(");303 int i = 0;304 for (Class<?> p : m.getParameterTypes()) {305 if (i++ > 0) {306 buf.append(", ");307 }308 buf.append(p.getName());309 }310 buf.append(")");311 return buf.toString();312 }313 @Override314 public String toString() {315 return "VerboseReporter{" + "suiteName=" + suiteName + '}';316 }317}...

Full Screen

Full Screen

Source:TestNGRunner.java Github

copy

Full Screen

...68 testng.addListener(new XMLReporter());69 testng.addListener(new EmailableReporter());70 // ... except this replaces JUnitReportReporter ...71 testng.addListener(new JUnitReportReporterWithMethodParameters());72 // ... and we can't access TestNG verbosity, so we remove VerboseReporter73 testng.run();74 }75 writeResult(className, results);76 }77 }78 /** Guessing whether or not a class is a test class is an imperfect art form. */79 private boolean mightBeATestClass(Class<?> klass) {80 int klassModifiers = klass.getModifiers();81 // Test classes must be public, non-abstract, non-interface82 if (!Modifier.isPublic(klassModifiers)83 || Modifier.isInterface(klassModifiers)84 || Modifier.isAbstract(klassModifiers)) {85 return false;86 }...

Full Screen

Full Screen

Source:LoggingReporter.java Github

copy

Full Screen

...9 * IBM Corporation - initial API and implementation10 *******************************************************************************/11package com.ibm.ws.microprofile.reactive.messaging.fat.kafka.tck;12import java.util.logging.Logger;13import org.testng.reporters.VerboseReporter;14/**15 * TestNG reporter that logs using java.util.logging16 */17public class LoggingReporter extends VerboseReporter {18 private static final Logger LOGGER = Logger.getLogger(LoggingReporter.class.getName());19 public LoggingReporter() {20 super(""); // No message prefix21 }22 @Override23 protected void log(String message) {24 LOGGER.info(message);25 }26}...

Full Screen

Full Screen

Source:LogTestStatusListener.java Github

copy

Full Screen

1package eu.profinit.manta.connector.java.analysis;2import org.slf4j.Logger;3import org.slf4j.LoggerFactory;4import org.testng.ITestResult;5import org.testng.reporters.VerboseReporter;6public class LogTestStatusListener extends VerboseReporter {7 private static final Logger log = LoggerFactory.getLogger(LogTestStatusListener.class);8 public LogTestStatusListener() {9 super("");10 }11 @Override12 public void onTestSuccess(ITestResult tr) {13 super.onTestSuccess(tr);14 if (tr.getThrowable() != null) {15 log.trace("vvv Test successfully throw exception vvv", tr.getThrowable());16 log.trace("^^^ Test successfully throw exception ^^^");17 }18 }19 @Override20 protected void log(String message) {...

Full Screen

Full Screen

Source:VerboseLogReporter.java Github

copy

Full Screen

1package com.sequenceiq.it.cloudbreak.listener;2import org.slf4j.Logger;3import org.slf4j.LoggerFactory;4import org.testng.reporters.VerboseReporter;5class VerboseLogReporter extends VerboseReporter {6 private static final Logger LOG = LoggerFactory.getLogger(VerboseLogReporter.class);7 VerboseLogReporter() {8 super("[TestNG] ");9 }10 @Override11 protected void log(String message) {12 LOG.info(message.replaceAll("(?m)^", ""));13 }14}

Full Screen

Full Screen
copy
1@RunWith(SpringJUnit4ClassRunner.class)2@ContextConfiguration(classes = { ApplicationConfig.class, CachingConfig.class }, loader = AnnotationConfigContextLoader.class)3@PersistenceContext4@Transactional("hibernateTransactionManager")5public class EHCacheTest extends AbstractTransactionalJUnit4SpringContextTests {6}7
Full Screen

TestNG tutorial

TestNG is a Java-based open-source framework for test automation that includes various test types, such as unit testing, functional testing, E2E testing, etc. TestNG is in many ways similar to JUnit and NUnit. But in contrast to its competitors, its extensive features make it a lot more reliable framework. One of the major reasons for its popularity is its ability to structure tests and improve the scripts' readability and maintainability. Another reason can be the important characteristics like the convenience of using multiple annotations, reliance, and priority that make this framework popular among developers and testers for test design. You can refer to the TestNG tutorial to learn why you should choose the TestNG framework.

Chapters

  1. JUnit 5 vs. TestNG: Compare and explore the core differences between JUnit 5 and TestNG from the Selenium WebDriver viewpoint.
  2. Installing TestNG in Eclipse: Start installing the TestNG Plugin and learn how to set up TestNG in Eclipse to begin constructing a framework for your test project.
  3. Create TestNG Project in Eclipse: Get started with creating a TestNG project and write your first TestNG test script.
  4. Automation using TestNG: Dive into how to install TestNG in this Selenium TestNG tutorial, the fundamentals of developing an automation script for Selenium automation testing.
  5. Parallel Test Execution in TestNG: Here are some essential elements of parallel testing with TestNG in this Selenium TestNG tutorial.
  6. Creating TestNG XML File: Here is a step-by-step tutorial on creating a TestNG XML file to learn why and how it is created and discover how to run the TestNG XML file being executed in parallel.
  7. Automation with Selenium, Cucumber & TestNG: Explore for an in-depth tutorial on automation using Selenium, Cucumber, and TestNG, as TestNG offers simpler settings and more features.
  8. JUnit Selenium Tests using TestNG: Start running your regular and parallel tests by looking at how to run test cases in Selenium using JUnit and TestNG without having to rewrite the tests.
  9. Group Test Cases in TestNG: Along with the explanation and demonstration using relevant TestNG group examples, learn how to group test cases in TestNG.
  10. Prioritizing Tests in TestNG: Get started with how to prioritize test cases in TestNG for Selenium automation testing.
  11. Assertions in TestNG: Examine what TestNG assertions are, the various types of TestNG assertions, and situations that relate to Selenium automated testing.
  12. DataProviders in TestNG: Deep dive into learning more about TestNG's DataProvider and how to effectively use it in our test scripts for Selenium test automation.
  13. Parameterization in TestNG: Here are the several parameterization strategies used in TestNG tests and how to apply them in Selenium automation scripts.
  14. TestNG Listeners in Selenium WebDriver: Understand the various TestNG listeners to utilize them effectively for your next plan when working with TestNG and Selenium automation.
  15. TestNG Annotations: Learn more about the execution order and annotation attributes, and refer to the prerequisites required to set up TestNG.
  16. TestNG Reporter Log in Selenium: Find out how to use the TestNG Reporter Log and learn how to eliminate the need for external software with TestNG Reporter Class to boost productivity.
  17. TestNG Reports in Jenkins: Discover how to generate TestNG reports in Jenkins if you want to know how to create, install, and share TestNG reports in Jenkins.

Certification

You can push your abilities to do automated testing using TestNG and advance your career by earning a TestNG certification. Check out our TestNG certification.

YouTube

Watch this complete tutorial to learn how you can leverage the capabilities of the TestNG framework for Selenium automation testing.

Run Testng automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

...Most popular Stackoverflow questions on VerboseReporter

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful