Black-box testing framework for code that uses the Omnibus.


License
AGPL-3.0

Documentation

Omnitest

Pub Package Build Status Coverage Status

To make testing Omnibus based programs easier, this package implements a function that can evaluate test files that contain a YAML representation of the tests that should be executed. Using this omnitest function you can greatly simplify your testing code.

Test configuration

An Omnibus testing configuration file looks as follows:

description: >
  General description of the module you are testing and what you are testing.

message-spec:
- test/messages/messages.yaml
- package:messages/messages.yaml

expect-onload:
# When the module is loaded a tracking HTTP request is fired.
- PUT http://tracking.api/random-message-generator

use-cases:
- description: >
    Trigger random message about terminator.
  http-client:
    https-only: true
  messages:
  # This event should trigger the module to publish a random message.
  - package.v1.mTriggerMyEvent:
      subject: terminator
    expect:
    # First the module requests a new random message.
    - package.v1.mGetRandomMessage:
        subject: terminator
      module-responses:
      # The module gets a random message from the random message API.
      - GET http://generator.api/message/terminator.json
      - package.v1.mRandomMessage:
          message: I'll be back!
    # A random message is now published as a result of the initial trigger.
    - package.v1.mFinalMessage:
        say: I'll be back!

The messages used in this test are described in this omnibuild template:

messages:
- name: mFinalMessage
  type: event
  properties:
  - name: say
    note: Something to say
    type: String
- name: mTriggerMyEvent
  type: event
  properties:
  - name: subject
    note: Subject for a random message
    type: String
- name: mGetRandomMessage
  type: request
  properties:
  - name: subject
    note: The random message subject
    type: String
- name: mRandomMessage
  type: response
  properties:
  - name: message
    note: The random message
    type: String

Test code

To run this test file, and use it form code coverage reports, you have to include it in your testing code. Omnitest is built to be used along with the test package. The test code with omnitest should look something like this:

library package.test.random_message_module_test;

import 'package:test/test.dart';
import 'package:omnitest/omnitest.dart';

import 'package:package/random_message_module.dart' as random_message_module;

void main() {
  test(
      'Test the random message module',
      omnitest(
          random_message_module.main, 'test/random_message_module_test.yaml'));
}

Enumerations

To test messages with enumerations you have to put the enumeration indices in the test data. In general this is not preferable since it makes the test data much less readable. A simple way to overcome this issue is to use YAML anchors. A convention for this is included below.

enums:
- MyEnumeration:
  - option1: &MyEnumeration.option1 0
  - option2: &MyEnumeration.option2 1
  - option3: &MyEnumeration.option3 2

use-cases:
- messages:
  - package.v1.mMessageWithEnum:
      option: *MyEnumeration.option1