Link Search Menu Expand Document

Assertions and Results

Table of Contents

  1. Assertions
  2. Results
    1. Assigning specific results
  3. Adding Messages to Results

Assertions

Assertions are used in Inferno to check the behavior under test. When an assertion fails, execution of that test ends, and it gets a failing result. The most basic form of an assertion is the assert method, which takes two arguments:

  • The first argument determines whether the assertion passes or fails. It will pass if the value is truthy (anything other than false or nil), and fail if the value is falsey (false or nil).
  • The second value is the message which will be displayed if the assertion fails.
test do
  run do
    assert 1 > 0, 'This assertion will never fail'
    assert 1 < 0, '1 is not less than 0'
  end
end

Inferno also implements more specific assertion to handle common cases, such as:

  • Verifying the http status code of a response.
  • Verifying that a string is valid JSON.
  • Validating a FHIR Resource.

Check out the assertions API documentation for all available assertions.

Results

Tests can have the following results in Inferno:

  • pass - Inferno was able to verify correct behavior.
  • fail - Inferno was able to verify incorrect behavior.
  • skip - Inferno was unable to verify correct or incorrect behavior. For instance, a test may need to validate a Condition resource, but none are available on the server. Inferno was not able to validate the resource, but the server is also not demonstrating incorrect behavior. A skip prevents a test session from passing because some behavior could not be verified.
  • omit - Inferno does not need to verify behavior. For example, an Implementation Guide may say that if a server does not do A, then it must do B. Inferno has verified that the server does A, so it does not make sense to verify B. An omit does not prevent a test session from passing because it indicates behavior that does not need to be verified.
  • error - Something unexpected happened and caused an internal server error. This indicates a problem in a test kit or in Inferno itself. You should contact the test kit author or the Inferno team.
  • wait - A test is waiting to receive an incoming request, and will resume once it is received.
  • cancel (not yet implemented)

Assigning specific results

Inferno provides methods to assign some specific results to a test:

  • pass/pass_if - These can be used to end test execution early.
  • skip/skip_if
  • omit/omit_if

The *_if methods take the same kind of arguments as assert, a value whose truthiness will be evaluated, and a message to be displayed. The other methods just take a message. For more information, view the results API documentation.

test do
  run do
    omit_if test_should_be_omitted, 'This test is being omitted because...'
    skip_if test_should_be_skipped, 'This test is being skipped because...'
    pass_if test_should_pass
    
    skip 'This test is being skipped'
  end
end

Adding Messages to Results

Test results can have error, warning, and info messages associated with them. Error messages are typically generated by failing assertions. You can use the warning and info messages to add those message types to a result, or to turn a failed assertion message into a warning or info message. Info and warning messages are dispayed in the UI, but do not affect the test result.

test do
  run do
    info 'This info message will be added to the result'
    info do
      assert false, %(
        This assert is inside an `info` block, so it will not halt test execution
        if it fails, and this will be an info message rather than an error
        message.
      )
    end
    
    warning 'This warning message will be added to the result'
    warning do
      assert false, %(
        This assert is inside a `warning` block, so it will not halt test
        execution if it fails, and this will be a warning message rather than an
        error message.
      )
    end
  end
end

info in the API docs

warning in the API docs