Class: Datadog::CI::Test
Overview
Represents a single part of a test run.
Instance Attribute Summary
Attributes inherited from Span
Instance Method Summary collapse
- #any_retry_passed? ⇒ Boolean
-
#failed!(exception: nil) ⇒ void
Sets the status of the span to “fail”.
-
#finish ⇒ void
Finishes the current test.
-
#is_retry? ⇒ Boolean
Returns “true” if test span represents a retry.
-
#itr_unskippable! ⇒ void
Marks this test as unskippable by the intelligent test runner.
-
#name ⇒ String
The name of the test.
-
#parameters ⇒ String?
Gets the parameters for this test (e.g. Cucumber example or RSpec specs) as a serialized JSON.
-
#passed! ⇒ void
Sets the status of the span to “pass”.
-
#set_parameters(arguments, metadata = {}) ⇒ void
Sets the parameters for this test (e.g. Cucumber example or RSpec specs).
-
#skipped!(exception: nil, reason: nil) ⇒ void
Sets the status of the span to “skip”.
-
#skipped_by_itr? ⇒ Boolean
Returns “true” if the test is skipped by the intelligent test runner.
-
#source_file ⇒ String?
Source file path of the test relative to git repository root.
-
#test_module_id ⇒ String
Span id of the running test module this test belongs to.
-
#test_session_id ⇒ String
Span id of the running test session this test belongs to.
-
#test_suite ⇒ Datadog::CI::TestSuite?
Running test suite that this test is part of (if any).
-
#test_suite_id ⇒ String
Span id of the running test suite this test belongs to.
-
#test_suite_name ⇒ String
Name of the running test suite this test belongs to.
Methods inherited from Span
#clear_tag, #failed?, #get_tag, #git_branch, #git_commit_sha, #git_repository_url, #id, #initialize, #os_architecture, #os_platform, #os_version, #passed?, #runtime_name, #runtime_version, #service, #set_default_tags, #set_environment_runtime_tags, #set_metric, #set_tag, #set_tags, #skipped?, #to_s, #trace_id, #type, #undefined?
Constructor Details
This class inherits a constructor from Datadog::CI::Span
Instance Method Details
#any_retry_passed? ⇒ Boolean
149 150 151 |
# File 'lib/datadog/ci/test.rb', line 149 def any_retry_passed? !!test_suite&.any_test_retry_passed?(test_id) end |
#failed!(exception: nil) ⇒ void
This method returns an undefined value.
Sets the status of the span to “fail”.
112 113 114 115 116 |
# File 'lib/datadog/ci/test.rb', line 112 def failed!(exception: nil) super record_test_result(Ext::Test::Status::FAIL) end |
#finish ⇒ void
This method returns an undefined value.
Finishes the current test.
22 23 24 25 26 |
# File 'lib/datadog/ci/test.rb', line 22 def finish test_visibility.deactivate_test super end |
#is_retry? ⇒ Boolean
Returns “true” if test span represents a retry.
75 76 77 |
# File 'lib/datadog/ci/test.rb', line 75 def is_retry? get_tag(Ext::Test::TAG_IS_RETRY) == "true" end |
#itr_unskippable! ⇒ void
This method returns an undefined value.
Marks this test as unskippable by the intelligent test runner. This must be done before the test execution starts.
Examples of tests that should be unskippable:
-
tests that read files from disk
-
tests that make network requests
-
tests that call external processes
-
tests that use forking or threading
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/datadog/ci/test.rb', line 89 def itr_unskippable! TestOptimisation::Telemetry.itr_unskippable set_tag(Ext::Test::TAG_ITR_UNSKIPPABLE, "true") if skipped_by_itr? clear_tag(Ext::Test::TAG_ITR_SKIPPED_BY_ITR) TestOptimisation::Telemetry.itr_forced_run set_tag(Ext::Test::TAG_ITR_FORCED_RUN, "true") end end |
#name ⇒ String
Returns the name of the test.
16 17 18 |
# File 'lib/datadog/ci/test.rb', line 16 def name get_tag(Ext::Test::TAG_NAME) end |
#parameters ⇒ String?
Gets the parameters for this test (e.g. Cucumber example or RSpec specs) as a serialized JSON.
144 145 146 |
# File 'lib/datadog/ci/test.rb', line 144 def parameters get_tag(Ext::Test::TAG_PARAMETERS) end |
#passed! ⇒ void
This method returns an undefined value.
Sets the status of the span to “pass”.
103 104 105 106 107 |
# File 'lib/datadog/ci/test.rb', line 103 def passed! super record_test_result(Ext::Test::Status::PASS) end |
#set_parameters(arguments, metadata = {}) ⇒ void
This method returns an undefined value.
Sets the parameters for this test (e.g. Cucumber example or RSpec specs). Parameters are needed to compute test fingerprint to distinguish between different tests having same names.
134 135 136 137 138 |
# File 'lib/datadog/ci/test.rb', line 134 def set_parameters(arguments, = {}) return if arguments.nil? set_tag(Ext::Test::TAG_PARAMETERS, Utils::TestRun.test_parameters(arguments: arguments, metadata: )) end |
#skipped!(exception: nil, reason: nil) ⇒ void
This method returns an undefined value.
Sets the status of the span to “skip”.
122 123 124 125 126 |
# File 'lib/datadog/ci/test.rb', line 122 def skipped!(exception: nil, reason: nil) super record_test_result(Ext::Test::Status::SKIP) end |
#skipped_by_itr? ⇒ Boolean
Returns “true” if the test is skipped by the intelligent test runner.
69 70 71 |
# File 'lib/datadog/ci/test.rb', line 69 def skipped_by_itr? get_tag(Ext::Test::TAG_ITR_SKIPPED_BY_ITR) == "true" end |
#source_file ⇒ String?
Source file path of the test relative to git repository root.
63 64 65 |
# File 'lib/datadog/ci/test.rb', line 63 def source_file get_tag(Ext::Test::TAG_SOURCE_FILE) end |
#test_module_id ⇒ String
Span id of the running test module this test belongs to.
50 51 52 |
# File 'lib/datadog/ci/test.rb', line 50 def test_module_id get_tag(Ext::Test::TAG_TEST_MODULE_ID) end |
#test_session_id ⇒ String
Span id of the running test session this test belongs to.
56 57 58 |
# File 'lib/datadog/ci/test.rb', line 56 def test_session_id get_tag(Ext::Test::TAG_TEST_SESSION_ID) end |
#test_suite ⇒ Datadog::CI::TestSuite?
Running test suite that this test is part of (if any).
31 32 33 34 |
# File 'lib/datadog/ci/test.rb', line 31 def test_suite suite_name = test_suite_name CI.active_test_suite(suite_name) if suite_name end |
#test_suite_id ⇒ String
Span id of the running test suite this test belongs to.
38 39 40 |
# File 'lib/datadog/ci/test.rb', line 38 def test_suite_id get_tag(Ext::Test::TAG_TEST_SUITE_ID) end |