Skip to content

Commit

Permalink
Fix NPE when tracing named parametrized tests in JUnit 4 instrumentat…
Browse files Browse the repository at this point in the history
…ion (#6125)
  • Loading branch information
nikita-tkachenko-datadog authored Nov 3, 2023
1 parent 88eba91 commit 96bc2b9
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,9 @@ public static boolean isTestSuiteDescription(final Description description) {

public static boolean isSuiteContainingChildren(final Description description) {
Class<?> testClass = description.getTestClass();
if (testClass == null) {
return false;
}
for (Method method : testClass.getMethods()) {
if (method.getAnnotation(Test.class) != null) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,8 @@ class JUnit4Test extends CiVisibilityTest {
})

where:
testTags_0 = [(Tags.TEST_PARAMETERS): '{"metadata":{"test_name":"parameterized_test_succeed[0]"}}']
testTags_1 = [(Tags.TEST_PARAMETERS): '{"metadata":{"test_name":"parameterized_test_succeed[1]"}}']
testTags_0 = [(Tags.TEST_PARAMETERS): '{"metadata":{"test_name":"parameterized_test_succeed[str1]"}}']
testTags_1 = [(Tags.TEST_PARAMETERS): '{"metadata":{"test_name":"parameterized_test_succeed[\\"str2\\"]"}}']
}

def "test ITR skipping"() {
Expand Down Expand Up @@ -529,11 +529,11 @@ class JUnit4Test extends CiVisibilityTest {

where:
testTags_0 = [
(Tags.TEST_PARAMETERS): '{"metadata":{"test_name":"parameterized_test_succeed[0]"}}',
(Tags.TEST_PARAMETERS): '{"metadata":{"test_name":"parameterized_test_succeed[str1]"}}',
(Tags.TEST_SKIP_REASON): "Skipped by Datadog Intelligent Test Runner",
(Tags.TEST_SKIPPED_BY_ITR): true
]
testTags_1 = [(Tags.TEST_PARAMETERS): '{"metadata":{"test_name":"parameterized_test_succeed[1]"}}']
testTags_1 = [(Tags.TEST_PARAMETERS): '{"metadata":{"test_name":"parameterized_test_succeed[\\"str2\\"]"}}']
}

def "test ITR unskippable"() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@RunWith(Parameterized.class)
public class TestParameterized {

@Parameterized.Parameters
@Parameterized.Parameters(name = "{1}")
public static Collection<Object[]> data() {
return Arrays.asList(
new Object[][] {{new ParamObject(), "str1", 0}, {new ParamObject(), "\"str2\"", 1}});
Expand Down

0 comments on commit 96bc2b9

Please sign in to comment.