diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index ea85d122e..a2cd1f016 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -48,7 +48,7 @@ jobs:
java-version: 11
distribution: temurin
- - run: sudo apt-get install socat ${{ matrix.packages }}
+ - run: sudo apt-get update && sudo apt-get install socat ${{ matrix.packages }}
- run: mvn -P "${{ matrix.profile }}" --batch-mode
macos:
diff --git a/pom.xml b/pom.xml
index f5a20a102..395e72022 100644
--- a/pom.xml
+++ b/pom.xml
@@ -52,6 +52,7 @@
4.12
+ 2.22.0
1.2.3
2.5.0
@@ -82,15 +83,21 @@
${dependency.nativelibloader.version}
- junit
- junit
- ${dependency.junit.version}
+ org.apache.logging.log4j
+ log4j-core
+ ${dependency.log4j.version}
test
- ch.qos.logback
- logback-classic
- ${dependency.logback.version}
+ org.apache.logging.log4j
+ log4j-slf4j-impl
+ ${dependency.log4j.version}
+ test
+
+
+ junit
+ junit
+ ${dependency.junit.version}
test
diff --git a/src/test/java/jssc/SerialNativeInterfaceTest.java b/src/test/java/jssc/SerialNativeInterfaceTest.java
index 541e2f753..8c8a7600f 100644
--- a/src/test/java/jssc/SerialNativeInterfaceTest.java
+++ b/src/test/java/jssc/SerialNativeInterfaceTest.java
@@ -1,5 +1,6 @@
package jssc;
+import jssc.junit.rules.DisplayMethodNameRule;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
@@ -13,7 +14,7 @@
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;
-public class SerialNativeInterfaceTest {
+public class SerialNativeInterfaceTest extends DisplayMethodNameRule {
@Test
public void testInitNativeInterface() {
diff --git a/src/test/java/jssc/VirtualPortTest.java b/src/test/java/jssc/VirtualPortTest.java
index 623aeb976..13bb419ef 100644
--- a/src/test/java/jssc/VirtualPortTest.java
+++ b/src/test/java/jssc/VirtualPortTest.java
@@ -24,12 +24,14 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;
+
+import jssc.junit.rules.DisplayMethodNameRule;
import jssc.junit.rules.VirtualPortRule;
import org.junit.Assume;
import org.junit.Rule;
import org.junit.Test;
-public class VirtualPortTest {
+public class VirtualPortTest extends DisplayMethodNameRule {
private static final String HELLO_WORLD = "Hello, world!";
diff --git a/src/test/java/jssc/bootpath/ManualBootLibraryPathFailedTest.java b/src/test/java/jssc/bootpath/ManualBootLibraryPathFailedTest.java
index 2ae9ea678..f7756378e 100644
--- a/src/test/java/jssc/bootpath/ManualBootLibraryPathFailedTest.java
+++ b/src/test/java/jssc/bootpath/ManualBootLibraryPathFailedTest.java
@@ -1,6 +1,7 @@
package jssc.bootpath;
import jssc.SerialNativeInterface;
+import jssc.junit.rules.DisplayMethodNameRule;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
@@ -16,7 +17,7 @@
* - maven-surefire-plugin DOES offer JVM unloading between classes using reuseForks=false
* - Unloading is needed due to NativeLoader.loadLibrary(...) calls System.loadLibrary(...) which is static
*/
-public class ManualBootLibraryPathFailedTest {
+public class ManualBootLibraryPathFailedTest extends DisplayMethodNameRule {
@Test
public void testBootPathOverride() {
String nativeLibDir = "/"; // This should be valid on all platforms
diff --git a/src/test/java/jssc/bootpath/ManualBootLibraryPathTest.java b/src/test/java/jssc/bootpath/ManualBootLibraryPathTest.java
index 77983d1b6..1abb7ea24 100644
--- a/src/test/java/jssc/bootpath/ManualBootLibraryPathTest.java
+++ b/src/test/java/jssc/bootpath/ManualBootLibraryPathTest.java
@@ -1,6 +1,7 @@
package jssc.bootpath;
import jssc.SerialNativeInterface;
+import jssc.junit.rules.DisplayMethodNameRule;
import org.junit.Test;
import org.scijava.nativelib.NativeLibraryUtil;
@@ -18,7 +19,7 @@
* - maven-surefire-plugin DOES offer JVM unloading between classes using reuseForks=false
* - Unloading is needed due to NativeLoader.loadLibrary(...) calls System.loadLibrary(...) which is static
*/
-public class ManualBootLibraryPathTest {
+public class ManualBootLibraryPathTest extends DisplayMethodNameRule {
@Test
public void testBootPathOverride() {
String nativeLibDir = NativeLibraryUtil.getPlatformLibraryPath(System.getProperty("user.dir") + "/target/cmake/natives/");
diff --git a/src/test/java/jssc/junit/rules/DisplayMethodNameRule.java b/src/test/java/jssc/junit/rules/DisplayMethodNameRule.java
new file mode 100644
index 000000000..a4e1c112a
--- /dev/null
+++ b/src/test/java/jssc/junit/rules/DisplayMethodNameRule.java
@@ -0,0 +1,22 @@
+package jssc.junit.rules;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.MarkerManager;
+import org.junit.Rule;
+import org.junit.rules.TestWatcher;
+import org.junit.runner.Description;
+
+/**
+ * Adds the method name to the JUnit logs, useful for debugging
+ */
+public class DisplayMethodNameRule {
+ @Rule
+ public TestWatcher methodWatcher = new TestWatcher() {
+ @Override
+ protected void starting(Description description) {
+ Logger log = LogManager.getLogger(description.getTestClass());
+ log.info(MarkerManager.getMarker("MethodName"), description.getMethodName());
+ }
+ };
+}
\ No newline at end of file
diff --git a/src/test/java/jssc/junit/rules/VirtualPortRule.java b/src/test/java/jssc/junit/rules/VirtualPortRule.java
index 7512d9cd6..f6dc448a9 100644
--- a/src/test/java/jssc/junit/rules/VirtualPortRule.java
+++ b/src/test/java/jssc/junit/rules/VirtualPortRule.java
@@ -32,16 +32,18 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
+
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
import jssc.SerialNativeInterface;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
public class VirtualPortRule implements TestRule {
- private static final Logger LOG = LoggerFactory.getLogger(VirtualPortRule.class);
+ private static final Logger LOG = LogManager.getLogger(VirtualPortRule.class);
private static final ExecutorService executor = Executors.newCachedThreadPool();
diff --git a/src/test/resources/log4j2.properties b/src/test/resources/log4j2.properties
new file mode 100644
index 000000000..ce58c24b1
--- /dev/null
+++ b/src/test/resources/log4j2.properties
@@ -0,0 +1,22 @@
+# Logging settings for unit tests
+
+# The root logger with appender name
+rootLogger=DEBUG,STDOUT,TESTNAME
+
+# Assign STDOUT a valid appender & define its layout
+appender.console.name=STDOUT
+appender.console.type=Console
+appender.console.layout.type=PatternLayout
+appender.console.layout.pattern=[%highlight{%p}{INFO=blue}] [%c{1}] %m%n
+
+# Make logs for Junit4 method names look like maven
+appender.testName.name=TESTNAME
+appender.testName.type=Console
+appender.testName.layout.type=PatternLayout
+appender.testName.layout.pattern=[%highlight{%p}{INFO=blue}] Running %c.%highlight{%m}{FATAL=bold,white, ERROR=bold,white, WARN=bold,white, INFO=bold,white, DEBUG=bold,white, TRACE=bold,white}%n
+appender.testName.filter.1.type=MarkerFilter
+appender.testName.filter.1.marker=MethodName
+appender.console.filter.1.type=MarkerFilter
+appender.console.filter.1.marker=MethodName
+appender.console.filter.1.onMatch=DENY
+appender.console.filter.1.onMismatch=ACCEPT
\ No newline at end of file