Skip to content

Commit

Permalink
[minitest] remove test suite prefix from the test name
Browse files Browse the repository at this point in the history
  • Loading branch information
anmarchenko committed Jan 16, 2024
1 parent 244ea8e commit 055cac5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
4 changes: 1 addition & 3 deletions lib/datadog/ci/contrib/minitest/hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ def before_setup
super
return unless datadog_configuration[:enabled]

test_name = "#{class_name}##{name}"

test_suite_name = Helpers.test_suite_name(self.class, name)
if Helpers.parallel?(self.class)
test_suite_name = "#{test_suite_name} (#{name} concurrently)"
Expand All @@ -27,7 +25,7 @@ def before_setup
source_file, line_number = method(name).source_location

CI.start_test(
test_name,
name,
test_suite_name,
tags: {
CI::Ext::Test::TAG_FRAMEWORK => Ext::FRAMEWORK,
Expand Down
34 changes: 16 additions & 18 deletions spec/datadog/ci/contrib/minitest/instrumentation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ def test_foo
klass.new(:test_foo).run

expect(span.type).to eq(Datadog::CI::Ext::AppTypes::TYPE_TEST)
expect(span.name).to eq("SomeTest#test_foo")
expect(span.resource).to eq("SomeTest#test_foo")
expect(span.name).to eq("test_foo")
expect(span.resource).to eq("test_foo")
expect(span.service).to eq("ltest")
expect(span.get_tag(Datadog::CI::Ext::Test::TAG_NAME)).to eq("SomeTest#test_foo")
expect(span.get_tag(Datadog::CI::Ext::Test::TAG_NAME)).to eq("test_foo")
expect(span.get_tag(Datadog::CI::Ext::Test::TAG_SUITE)).to eq(
"SomeTest at spec/datadog/ci/contrib/minitest/instrumentation_spec.rb"
)
Expand Down Expand Up @@ -92,9 +92,9 @@ def self.name
klass.new(method_name).run

expect(span.type).to eq(Datadog::CI::Ext::AppTypes::TYPE_TEST)
expect(span.resource).to eq("SomeSpec##{method_name}")
expect(span.resource).to eq(method_name)
expect(span.service).to eq("ltest")
expect(span.get_tag(Datadog::CI::Ext::Test::TAG_NAME)).to eq("SomeSpec##{method_name}")
expect(span.get_tag(Datadog::CI::Ext::Test::TAG_NAME)).to eq(method_name)
expect(span.get_tag(Datadog::CI::Ext::Test::TAG_SUITE)).to eq(
"SomeSpec at spec/datadog/ci/contrib/minitest/instrumentation_spec.rb"
)
Expand Down Expand Up @@ -496,7 +496,7 @@ def test_fail
end

it "traces test, test session, test module with failed status" do
expect(first_test_span.get_tag(Datadog::CI::Ext::Test::TAG_NAME)).to eq("SomeFailedTest#test_fail")
expect(first_test_span.get_tag(Datadog::CI::Ext::Test::TAG_NAME)).to eq("test_fail")
expect(first_test_span.get_tag(Datadog::CI::Ext::Test::TAG_STATUS)).to eq(
Datadog::CI::Ext::Test::Status::FAIL
)
Expand Down Expand Up @@ -538,21 +538,19 @@ class SomeSpec < Minitest::Spec
end
end

it "traces tests with unique names" do
it "traces tests with the same name but different test suites" do
test_names = test_spans.map { |span| span.get_tag(Datadog::CI::Ext::Test::TAG_NAME) }.sort

expect(test_names).to eq(
[
"SomeSpec#test_0001_does not fail",
"in context#test_0001_does not fail",
"in context::deeper context#test_0001_does not fail",
"in other context#test_0001_does not fail"
"test_0001_does not fail",
"test_0001_does not fail",
"test_0001_does not fail",
"test_0001_does not fail"
]
)
end

it "connects tests to different test suites (one per spec context)" do
test_suite_ids = test_spans.map { |span| span.get_tag(Datadog::CI::Ext::Test::TAG_TEST_SUITE_ID) }.uniq

test_suite_names = test_spans.map { |span| span.get_tag(Datadog::CI::Ext::Test::TAG_SUITE) }.sort

expect(test_suite_ids).to have(4).items
Expand Down Expand Up @@ -617,10 +615,10 @@ def test_b_2
test_names = test_spans.map { |span| span.get_tag(Datadog::CI::Ext::Test::TAG_NAME) }.sort
expect(test_names).to eq(
[
"TestA#test_a_1",
"TestA#test_a_2",
"TestB#test_b_1",
"TestB#test_b_2"
"test_a_1",
"test_a_2",
"test_b_1",
"test_b_2"
]
)

Expand Down

0 comments on commit 055cac5

Please sign in to comment.