Skip to content

Commit

Permalink
improve error logging for JUnit tests (#711)
Browse files Browse the repository at this point in the history
* print ILog messages to System logger in JUnit tests

* set trimStackTrace=false for tycho-surefire-plugin
  • Loading branch information
sebthom committed Jul 3, 2023
1 parent c5708d9 commit b0a8f71
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions org.eclipse.lsp4e.test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<artifactId>tycho-surefire-plugin</artifactId>
<version>${tycho-version}</version>
<configuration>
<trimStackTrace>false</trimStackTrace>
<testClass>org.eclipse.lsp4e.test.AllTests</testClass>
<useUIHarness>true</useUIHarness>
<useUIThread>true</useUIThread>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*******************************************************************************/
package org.eclipse.lsp4e.test;

import java.lang.System.Logger.Level;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -30,13 +31,23 @@ public class NoErrorLoggedRule extends TestWatcher {

public NoErrorLoggedRule(ILog log) {
this.log = log;
listener = (status, message) -> {
if (status.getSeverity() == IStatus.ERROR) {
final var logger = System.getLogger(log.getBundle().getSymbolicName());
listener = (status, unused) -> {
switch (status.getSeverity()) {
case IStatus.ERROR:
loggedErrors.add(status);
logger.log(Level.ERROR, status.toString(), status.getException());
break;
case IStatus.WARNING:
logger.log(Level.WARNING, status.toString(), status.getException());
break;
case IStatus.INFO:
logger.log(Level.INFO, status.toString(), status.getException());
break;
}
};
}

@Override
protected void starting(Description description) {
super.starting(description);
Expand Down

0 comments on commit b0a8f71

Please sign in to comment.