Skip to content

Commit 5167051

Browse files
authored
Merge pull request #49 from Nordstrom/pr/add-debug-logging
Add debug logging and assertion messages
2 parents 04f76c6 + 2ae34d0 commit 5167051

File tree

9 files changed

+38
-5
lines changed

9 files changed

+38
-5
lines changed

src/main/java/com/nordstrom/automation/junit/AtomicTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,12 @@ public Throwable getThrowable() {
107107
public boolean includes(FrameworkMethod method) {
108108
return particles.contains(method);
109109
}
110+
111+
/**
112+
* {@inheritDoc}
113+
*/
114+
@Override
115+
public String toString() {
116+
return description.toString();
117+
}
110118
}

src/main/java/com/nordstrom/automation/junit/CreateTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import java.util.concurrent.Callable;
66
import java.util.concurrent.ConcurrentHashMap;
77

8+
import org.slf4j.Logger;
9+
import org.slf4j.LoggerFactory;
10+
811
import com.google.common.base.Optional;
912

1013
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
@@ -22,6 +25,7 @@ public class CreateTest {
2225
private static final Map<Object, Object> TARGET_TO_RUNNER = new ConcurrentHashMap<>();
2326
private static final Map<Object, Object> RUNNER_TO_TARGET = new ConcurrentHashMap<>();
2427
private static final ThreadLocal<DepthGauge> DEPTH;
28+
private static final Logger LOGGER = LoggerFactory.getLogger(CreateTest.class);
2529

2630
static {
2731
objectWatcherLoader = ServiceLoader.load(TestObjectWatcher.class);
@@ -57,6 +61,7 @@ public static Object intercept(@This final Object runner,
5761
RUNNER_TO_TARGET.put(runner, testObj);
5862

5963
if (DEPTH.get().atGroundLevel()) {
64+
LOGGER.debug("testObjectCreated: {}", testObj);
6065
synchronized(objectWatcherLoader) {
6166
for (TestObjectWatcher watcher : objectWatcherLoader) {
6267
watcher.testObjectCreated(testObj, runner);

src/main/java/com/nordstrom/automation/junit/LifecycleHooks.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@
1212
import java.util.concurrent.Callable;
1313
import java.util.concurrent.ConcurrentMap;
1414

15-
import org.junit.Test;
1615
import org.junit.runner.Description;
1716
import org.junit.runner.notification.RunListener;
1817
import org.junit.runners.model.TestClass;
1918

2019
import com.google.common.base.Function;
2120
import com.google.common.base.Optional;
22-
import com.nordstrom.automation.junit.JUnitConfig.JUnitSettings;
2321
import com.nordstrom.common.base.UncheckedThrow;
2422
import com.nordstrom.common.file.PathUtils.ReportsDirectory;
2523

src/main/java/com/nordstrom/automation/junit/Run.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import org.junit.runner.Description;
1414
import org.junit.runner.notification.RunListener;
1515
import org.junit.runner.notification.RunNotifier;
16+
import org.slf4j.Logger;
17+
import org.slf4j.LoggerFactory;
1618

1719
import com.google.common.base.Optional;
1820

@@ -32,6 +34,7 @@ public class Run {
3234
private static final ServiceLoader<RunnerWatcher> runnerWatcherLoader;
3335
private static final Map<Object, Object> CHILD_TO_PARENT = new ConcurrentHashMap<>();
3436
private static final Set<RunNotifier> NOTIFIERS = new CopyOnWriteArraySet<>();
37+
private static final Logger LOGGER = LoggerFactory.getLogger(Run.class);
3538

3639
static {
3740
runnerStack = new ThreadLocal<Deque<Object>>() {
@@ -139,6 +142,7 @@ static boolean fireRunStarted(Object runner) {
139142
for (Object grandchild : grandchildren) {
140143
CHILD_TO_PARENT.put(grandchild, runner);
141144
}
145+
LOGGER.debug("runStarted: {}", runner);
142146
synchronized(runnerWatcherLoader) {
143147
for (RunnerWatcher watcher : runnerWatcherLoader) {
144148
watcher.runStarted(runner);
@@ -158,6 +162,7 @@ static boolean fireRunStarted(Object runner) {
158162
*/
159163
static boolean fireRunFinished(Object runner) {
160164
if (finishNotified.add(runner.toString())) {
165+
LOGGER.debug("runFinished: {}", runner);
161166
synchronized(runnerWatcherLoader) {
162167
for (RunnerWatcher watcher : runnerWatcherLoader) {
163168
watcher.runFinished(runner);

src/main/java/com/nordstrom/automation/junit/RunAnnouncer.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,16 @@
99
import org.junit.runner.notification.Failure;
1010
import org.junit.runner.notification.RunListener;
1111
import org.junit.runners.model.FrameworkMethod;
12+
import org.slf4j.Logger;
13+
import org.slf4j.LoggerFactory;
1214

1315
import com.google.common.base.Optional;
1416

1517
public class RunAnnouncer extends RunListener {
1618

1719
private static final ServiceLoader<RunWatcher> runWatcherLoader;
1820
private static final Map<Object, AtomicTest> RUNNER_TO_ATOMICTEST = new ConcurrentHashMap<>();
21+
private static final Logger LOGGER = LoggerFactory.getLogger(RunAnnouncer.class);
1922

2023
static {
2124
runWatcherLoader = ServiceLoader.load(RunWatcher.class);
@@ -26,6 +29,7 @@ public class RunAnnouncer extends RunListener {
2629
*/
2730
@Override
2831
public void testStarted(Description description) throws Exception {
32+
LOGGER.debug("testStarted: {}", description);
2933
AtomicTest atomicTest = getAtomicTestOf(description);
3034
synchronized(runWatcherLoader) {
3135
for (RunWatcher watcher : runWatcherLoader) {
@@ -39,6 +43,7 @@ public void testStarted(Description description) throws Exception {
3943
*/
4044
@Override
4145
public void testFinished(Description description) throws Exception {
46+
LOGGER.debug("testFinished: {}", description);
4247
AtomicTest atomicTest = getAtomicTestOf(description);
4348
synchronized(runWatcherLoader) {
4449
for (RunWatcher watcher : runWatcherLoader) {
@@ -52,6 +57,7 @@ public void testFinished(Description description) throws Exception {
5257
*/
5358
@Override
5459
public void testFailure(Failure failure) throws Exception {
60+
LOGGER.debug("testFailure: {}", failure);
5561
AtomicTest atomicTest = setTestFailure(failure);
5662
synchronized(runWatcherLoader) {
5763
for (RunWatcher watcher : runWatcherLoader) {
@@ -65,6 +71,7 @@ public void testFailure(Failure failure) throws Exception {
6571
*/
6672
@Override
6773
public void testAssumptionFailure(Failure failure) {
74+
LOGGER.debug("testAssumptionFailure: {}", failure);
6875
AtomicTest atomicTest = setTestFailure(failure);
6976
synchronized(runWatcherLoader) {
7077
for (RunWatcher watcher : runWatcherLoader) {
@@ -78,6 +85,7 @@ public void testAssumptionFailure(Failure failure) {
7885
*/
7986
@Override
8087
public void testIgnored(Description description) throws Exception {
88+
LOGGER.debug("testIgnored: {}", description);
8189
AtomicTest atomicTest = getAtomicTestOf(description);
8290
synchronized(runWatcherLoader) {
8391
for (RunWatcher watcher : runWatcherLoader) {

src/main/java/com/nordstrom/automation/junit/RunReflectiveCall.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import org.junit.BeforeClass;
1414
import org.junit.Test;
1515
import org.junit.runners.model.FrameworkMethod;
16+
import org.slf4j.Logger;
17+
import org.slf4j.LoggerFactory;
1618

1719
import com.google.common.base.Function;
1820
import com.google.common.base.Optional;
@@ -32,6 +34,7 @@ public class RunReflectiveCall {
3234
private static final ServiceLoader<MethodWatcher> methodWatcherLoader;
3335
private static final ThreadLocal<ConcurrentMap<Integer, DepthGauge>> methodDepth;
3436
private static final Function<Integer, DepthGauge> newInstance;
37+
private static final Logger LOGGER = LoggerFactory.getLogger(RunReflectiveCall.class);
3538

3639
static {
3740
methodWatcherLoader = ServiceLoader.load(MethodWatcher.class);
@@ -161,6 +164,9 @@ private static boolean fireBeforeInvocation(Object runner, Object target, Framew
161164
if ((runner != null) && (method != null)) {
162165
DepthGauge depthGauge = LifecycleHooks.computeIfAbsent(methodDepth.get(), methodHash(runner, method), newInstance);
163166
if (0 == depthGauge.increaseDepth()) {
167+
if (LOGGER.isDebugEnabled()) {
168+
LOGGER.debug("beforeInvocation: {}", LifecycleHooks.invoke(runner, "describeChild", method));
169+
}
164170
synchronized(methodWatcherLoader) {
165171
for (MethodWatcher watcher : methodWatcherLoader) {
166172
watcher.beforeInvocation(runner, target, method, params);
@@ -187,6 +193,9 @@ private static boolean fireAfterInvocation(Object runner, Object target, Framewo
187193
if ((runner != null) && (method != null)) {
188194
DepthGauge depthGauge = LifecycleHooks.computeIfAbsent(methodDepth.get(), methodHash(runner, method), newInstance);
189195
if (0 == depthGauge.decreaseDepth()) {
196+
if (LOGGER.isDebugEnabled()) {
197+
LOGGER.debug("afterInvocation: {}", LifecycleHooks.invoke(runner, "describeChild", method));
198+
}
190199
synchronized(methodWatcherLoader) {
191200
for (MethodWatcher watcher : methodWatcherLoader) {
192201
watcher.afterInvocation(runner, target, method, thrown);

src/test/java/com/nordstrom/automation/junit/AutomaticRetryFailing.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public class AutomaticRetryFailing {
99
@Test
1010
public void testFailed() {
1111
System.out.println("testFailed");
12-
assertTrue(false);
12+
assertTrue("testFailed", false);
1313
}
1414

1515
}

src/test/java/com/nordstrom/automation/junit/AutomaticRetryNoRetry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class AutomaticRetryNoRetry {
1212
@NoRetry
1313
public void testNoRetry() {
1414
System.out.println("testNoRetry: " + count);
15-
assertTrue(count++ > 0);
15+
assertTrue("testNoRetry: " + count, count++ > 0);
1616
}
1717

1818
}

src/test/java/com/nordstrom/automation/junit/AutomaticRetryPassOnRetry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class AutomaticRetryPassOnRetry {
1111
@Test
1212
public void testPassOnRetry() {
1313
System.out.println("testPassOnRetry: " + count);
14-
assertTrue(count++ > 0);
14+
assertTrue("testPassOnRetry: " + count, count++ > 0);
1515
}
1616

1717
}

0 commit comments

Comments
 (0)