Add a TestRunner that will print test names to stdout
authorAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Wed, 29 Jul 2015 22:52:11 +0000 (18:52 -0400)
committerAlexandre Montplaisir <alexmonthy@voxpopuli.im>
Wed, 29 Jul 2015 23:07:26 +0000 (19:07 -0400)
Eases debugging a bunch.

Signed-off-by: Alexandre Montplaisir <alexmonthy@voxpopuli.im>
src/test/java/org/lttng/ust/agent/integration/EnabledEventsTestBase.java
src/test/java/org/lttng/ust/agent/integration/MultiSessionTestBase.java
src/test/java/org/lttng/ust/agent/integration/jul/JulLegacyApiTest.java
src/test/java/org/lttng/ust/agent/integration/log4j/Log4jLegacyApiTest.java
src/test/java/org/lttng/ust/agent/utils/TestPrintRunner.java [new file with mode: 0644]

index 49ee622ff96d64aa14a0a81a91ecf1a83eb42a84..fcbc589eb7eb00d8867744abe471eb7c372cd0dd 100644 (file)
@@ -27,14 +27,17 @@ import java.util.List;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.lttng.ust.agent.ILttngHandler;
 import org.lttng.ust.agent.utils.LttngSession;
 import org.lttng.ust.agent.utils.LttngSession.Domain;
+import org.lttng.ust.agent.utils.TestPrintRunner;
 
 /**
  * Base abstract class to implement all sorts of integration tests verifying the
  * presence of enabled events in resulting traces.
  */
+@RunWith(TestPrintRunner.class)
 public abstract class EnabledEventsTestBase {
 
     protected static final String EVENT_NAME_A = "EventA";
index cb04e7ad0b64e9d0790ccffaef704a6c20175e2f..2330a31f908ad5511341085e79152709a086c161 100644 (file)
@@ -27,13 +27,16 @@ import java.util.List;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.lttng.ust.agent.ILttngHandler;
 import org.lttng.ust.agent.utils.LttngSession;
 import org.lttng.ust.agent.utils.LttngSession.Domain;
+import org.lttng.ust.agent.utils.TestPrintRunner;
 
 /**
  * Base abstract class for tests with multiple concurrent tracing sessions
  */
+@RunWith(TestPrintRunner.class)
 public abstract class MultiSessionTestBase {
 
     protected static final String EVENT_NAME_A = "EventA";
index 5f6a9a0b6cd235b95c4ceb60a426ae912555827c..f69aff359657bc973193934316d9b5741b6b1b46 100644 (file)
@@ -34,15 +34,18 @@ import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.lttng.ust.agent.ILttngHandler;
 import org.lttng.ust.agent.LTTngAgent;
 import org.lttng.ust.agent.utils.LttngSession;
 import org.lttng.ust.agent.utils.LttngSession.Domain;
 import org.lttng.ust.agent.utils.MiscTestUtils;
+import org.lttng.ust.agent.utils.TestPrintRunner;
 
 /**
  * Enabled events test for the LTTng-UST JUL log handler, using the legacy API.
  */
+@RunWith(TestPrintRunner.class)
 @SuppressWarnings("deprecation")
 public class JulLegacyApiTest {
 
index 6dcc30f0d3a624481b640eeba90710d35ac361cf..8d4a6fa49f64f5ea308c05ae468e8fe041958615 100644 (file)
@@ -34,16 +34,19 @@ import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.lttng.ust.agent.ILttngHandler;
 import org.lttng.ust.agent.LTTngAgent;
 import org.lttng.ust.agent.utils.LttngSession;
 import org.lttng.ust.agent.utils.LttngSession.Domain;
 import org.lttng.ust.agent.utils.MiscTestUtils;
+import org.lttng.ust.agent.utils.TestPrintRunner;
 
 /**
  * Enabled events test for the LTTng-UST Log4j log handler, using the legacy
  * API.
  */
+@RunWith(TestPrintRunner.class)
 @SuppressWarnings("deprecation")
 public class Log4jLegacyApiTest {
 
diff --git a/src/test/java/org/lttng/ust/agent/utils/TestPrintRunner.java b/src/test/java/org/lttng/ust/agent/utils/TestPrintRunner.java
new file mode 100644 (file)
index 0000000..4a38b74
--- /dev/null
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2015, EfficiOS Inc., Alexandre Montplaisir <alexmonthy@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.lttng.ust.agent.utils;
+
+import org.junit.runner.Description;
+import org.junit.runner.notification.Failure;
+import org.junit.runner.notification.RunListener;
+import org.junit.runner.notification.RunNotifier;
+import org.junit.runners.BlockJUnit4ClassRunner;
+import org.junit.runners.model.InitializationError;
+
+/**
+ * Test runner that will print the name of the test being run to stdout.
+ *
+ * Thanks to http://stackoverflow.com/a/27070843/4227853 for the tips.
+ *
+ * @author Alexandre Montplaisir
+ */
+public class TestPrintRunner extends BlockJUnit4ClassRunner {
+
+    /**
+     * Consructor
+     *
+     * @param klass
+     * @throws InitializationError
+     */
+    public TestPrintRunner(Class<?> klass) throws InitializationError {
+        super(klass);
+    }
+
+    @Override
+    public void run(RunNotifier notifier) {
+        notifier.addListener(new TestPrintListener());
+        super.run(notifier);
+    }
+
+    /**
+     * Listener that will print the class and test name to stdout.
+     */
+    public static class TestPrintListener extends RunListener {
+
+        @Override
+        public void testStarted(Description description) {
+            System.out.println("Running " + getTestName(description));
+        }
+
+        @Override
+        public void testAssumptionFailure(Failure failure) {
+            System.out.println("SKIPPING TEST: " + getTestName(failure.getDescription()));
+            System.out.println(failure.getMessage());
+        }
+
+        /**
+         * Get the className#methodName from a Description.
+         */
+        private static String getTestName(Description description) {
+            return description.getClassName() + '#' + description.getMethodName();
+        }
+    }
+
+}
This page took 0.025896 seconds and 4 git commands to generate.