Class: Datadog::CI::Test

Inherits:
Span
  • Object
show all
Defined in:
lib/datadog/ci/test.rb

Overview

Represents a single part of a test run.

Instance Attribute Summary

Attributes inherited from Span

#tracer_span

Instance Method Summary collapse

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

#failed!(exception: nil) ⇒ void

This method returns an undefined value.

Sets the status of the span to "fail".

Parameters:

  • exception (Exception) (defaults to: nil)

    the exception that caused the test to fail.



101
102
103
104
105
# File 'lib/datadog/ci/test.rb', line 101

def failed!(exception: nil)
  super

  record_test_result(Ext::Test::Status::FAIL)
end

#finishvoid

This method returns an undefined value.

Finishes the current test.



21
22
23
24
25
# File 'lib/datadog/ci/test.rb', line 21

def finish
  test_visibility.deactivate_test

  super
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


82
83
84
85
86
87
88
# File 'lib/datadog/ci/test.rb', line 82

def itr_unskippable!
  set_tag(Ext::Test::TAG_ITR_UNSKIPPABLE, "true")
  if skipped_by_itr?
    clear_tag(Ext::Test::TAG_ITR_SKIPPED_BY_ITR)
    set_tag(Ext::Test::TAG_ITR_FORCED_RUN, "true")
  end
end

#nameString

Returns the name of the test.

Returns:

  • (String)

    the name of the test.



15
16
17
# File 'lib/datadog/ci/test.rb', line 15

def name
  get_tag(Ext::Test::TAG_NAME)
end

#parametersString?

Gets the parameters for this test (e.g. Cucumber example or RSpec specs) as a serialized JSON.

Returns:

  • (String)

    the serialized JSON of the parameters

  • (nil)

    if this test does not have parameters



133
134
135
# File 'lib/datadog/ci/test.rb', line 133

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".



92
93
94
95
96
# File 'lib/datadog/ci/test.rb', line 92

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.

Parameters:

  • arguments (Hash)

    the arguments that test accepts as key-value hash

  • metadata (Hash) (defaults to: {})

    optional metadata



123
124
125
126
127
# File 'lib/datadog/ci/test.rb', line 123

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".

Parameters:

  • exception (Exception) (defaults to: nil)

    the exception that caused the test to fail.

  • reason (String) (defaults to: nil)

    the reason why the test was skipped.



111
112
113
114
115
# File 'lib/datadog/ci/test.rb', line 111

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.

Returns:

  • (Boolean)

    true if the test is skipped by the intelligent test runner, false otherwise.



68
69
70
# File 'lib/datadog/ci/test.rb', line 68

def skipped_by_itr?
  get_tag(Ext::Test::TAG_ITR_SKIPPED_BY_ITR) == "true"
end

#source_fileString?

Source file path of the test relative to git repository root.

Returns:

  • (String)

    the source file path of the test

  • (nil)

    if the source file path is not found



62
63
64
# File 'lib/datadog/ci/test.rb', line 62

def source_file
  get_tag(Ext::Test::TAG_SOURCE_FILE)
end

#test_module_idString

Span id of the running test module this test belongs to.

Returns:

  • (String)

    the span id of the test module.



49
50
51
# File 'lib/datadog/ci/test.rb', line 49

def test_module_id
  get_tag(Ext::Test::TAG_TEST_MODULE_ID)
end

#test_session_idString

Span id of the running test session this test belongs to.

Returns:

  • (String)

    the span id of the test session.



55
56
57
# File 'lib/datadog/ci/test.rb', line 55

def test_session_id
  get_tag(Ext::Test::TAG_TEST_SESSION_ID)
end

#test_suiteDatadog::CI::TestSuite?

Running test suite that this test is part of (if any).

Returns:



30
31
32
33
# File 'lib/datadog/ci/test.rb', line 30

def test_suite
  suite_name = test_suite_name
  CI.active_test_suite(suite_name) if suite_name
end

#test_suite_idString

Span id of the running test suite this test belongs to.

Returns:

  • (String)

    the span id of the test suite.



37
38
39
# File 'lib/datadog/ci/test.rb', line 37

def test_suite_id
  get_tag(Ext::Test::TAG_TEST_SUITE_ID)
end

#test_suite_nameString

Name of the running test suite this test belongs to.

Returns:

  • (String)

    the name of the test suite.



43
44
45
# File 'lib/datadog/ci/test.rb', line 43

def test_suite_name
  get_tag(Ext::Test::TAG_SUITE)
end