-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test suite level visibility for JUnit 3.8 test cases (#6320)
- Loading branch information
1 parent
4d0b113
commit 3fe1b2d
Showing
7 changed files
with
322 additions
and
109 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
...src/main/java/datadog/trace/instrumentation/junit4/JUnit38SuiteEventsInstrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package datadog.trace.instrumentation.junit4; | ||
|
||
import static datadog.trace.agent.tooling.bytebuddy.matcher.NameMatchers.named; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
|
||
import com.google.auto.service.AutoService; | ||
import datadog.trace.agent.tooling.Instrumenter; | ||
import java.util.List; | ||
import junit.framework.TestCase; | ||
import net.bytebuddy.asm.Advice; | ||
import org.junit.rules.RuleChain; | ||
import org.junit.runner.Runner; | ||
import org.junit.runner.notification.RunListener; | ||
import org.junit.runner.notification.RunNotifier; | ||
|
||
/** Supports suite started/finished events for {@link TestCase} subclasses. */ | ||
@AutoService(Instrumenter.class) | ||
public class JUnit38SuiteEventsInstrumentation extends Instrumenter.CiVisibility | ||
implements Instrumenter.ForSingleType { | ||
|
||
public JUnit38SuiteEventsInstrumentation() { | ||
super("ci-visibility", "junit-4", "junit-38"); | ||
} | ||
|
||
@Override | ||
public String instrumentedType() { | ||
return "org.junit.internal.runners.JUnit38ClassRunner"; | ||
} | ||
|
||
@Override | ||
public String[] helperClassNames() { | ||
return new String[] { | ||
packageName + ".TestEventsHandlerHolder", | ||
packageName + ".SkippedByItr", | ||
packageName + ".JUnit4Utils", | ||
packageName + ".TracingListener", | ||
packageName + ".JUnit4TracingListener", | ||
}; | ||
} | ||
|
||
@Override | ||
public void adviceTransformations(AdviceTransformation transformation) { | ||
transformation.applyAdvice( | ||
named("run").and(takesArgument(0, named("org.junit.runner.notification.RunNotifier"))), | ||
JUnit38SuiteEventsInstrumentation.class.getName() + "$JUnit38SuiteEventsAdvice"); | ||
} | ||
|
||
public static class JUnit38SuiteEventsAdvice { | ||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static void fireSuiteStartedEvent( | ||
@Advice.Argument(0) final RunNotifier runNotifier, @Advice.This final Runner runner) { | ||
final List<RunListener> runListeners = JUnit4Utils.runListenersFromRunNotifier(runNotifier); | ||
if (runListeners == null) { | ||
return; | ||
} | ||
|
||
for (final RunListener listener : runListeners) { | ||
TracingListener tracingListener = JUnit4Utils.toTracingListener(listener); | ||
if (tracingListener != null) { | ||
tracingListener.testSuiteStarted(runner.getDescription()); | ||
} | ||
} | ||
} | ||
|
||
@Advice.OnMethodExit(suppress = Throwable.class) | ||
public static void fireSuiteFinishedEvent( | ||
@Advice.Argument(0) final RunNotifier runNotifier, @Advice.This final Runner runner) { | ||
final List<RunListener> runListeners = JUnit4Utils.runListenersFromRunNotifier(runNotifier); | ||
if (runListeners == null) { | ||
return; | ||
} | ||
|
||
for (final RunListener listener : runListeners) { | ||
TracingListener tracingListener = JUnit4Utils.toTracingListener(listener); | ||
if (tracingListener != null) { | ||
tracingListener.testSuiteFinished(runner.getDescription()); | ||
} | ||
} | ||
} | ||
|
||
// JUnit 4.10 and above | ||
public static void muzzleCheck(final RuleChain ruleChain) { | ||
ruleChain.apply(null, null); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
dd-java-agent/instrumentation/junit-4.10/src/test/java/org/example/TestSucceedLegacy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.example; | ||
|
||
import junit.framework.TestCase; | ||
|
||
public class TestSucceedLegacy extends TestCase { | ||
|
||
public void test_succeed() { | ||
assertTrue(true); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
dd-java-agent/instrumentation/junit-4.10/src/test/resources/test-legacy/coverages.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[ ] |
Oops, something went wrong.