Skip to content

How to create integration test

Ilfat edited this page May 11, 2017 · 1 revision

How to create integration test

Introduction

Here you find information how to create integration test, where to store integration test

Where

Integration tests are kept in MDBCI_DIRECTORY/spec/integration folder.

How to name tests

Create ruby file like this: CUSTOM_TEST_NAME_spec.rb in integration tests folder

Example of test

Integration test example: https://github.com/OSLL/mdbci/blob/integration/spec/integration/6819_show_box_info_spec.rb

Here you can see block like:


executeShellCommandsAndTestExitCode ([
  {'shell_command'=>'./mdbci show boxinfo --box-name ubuntu_trusty_vbox --field platform', 'expectation'=>0},
  {'shell_command'=>'./mdbci show boxinfo --box-name ubuntu_trusty_vbox', 'expectation'=>0},
  {'shell_command'=>'./mdbci show boxinfo --box-name ubuntu_trusty_vbox --field', 'expectation'=>1},
  {'shell_command'=>'./mdbci show boxinfo --box-name ubuntu_trusty_vbox --field WRONG', 'expectation'=>1},
  {'shell_command'=>'./mdbci show boxinfo --box-name WRONG --field platform', 'expectation'=>1},
  {'shell_command'=>'./mdbci show boxinfo --box-name WRONG --field WRONG', 'expectation'=>1},
  {'shell_command'=>'./mdbci show boxinfo --box-name WRONG', 'expectation'=>1}
])

Method executeShellCommandsAndTestExitCode expects an array with hashes. Hashes contains bash command and exit code of command:


[{'shell_command'=>'ls', 'expectation'=>0}]

Here we say: ’let’s test ls command and check it’s exit code to be equal to zero’

Add tests to test set

If test non parametrized add next line to file MDBCI_DIRECTORY/spec/integration_tasks.rb like:


namespace :run_integration do
  ...
  task :task_CUSTOM_TEST_NAME do |t| RakeTaskManager.new(t).run_integration(PROVIDER_ARGUMENT) end
  ...
end

If test parametrized add next line to file MDBCI_DIRECTORY/spec/integration_parametrized_tasks.rb:


namespace :run_integration_parametrized do
  ...
  task :task_CUSTOM_TEST_NAME do |t| RakeTaskManager.new(t).run_integration_parametrized(PROVIDER_ARGUMENT) end
  ...
end

CUSTOM_TEST_NAME is a name of file with test from integration tests directory but without postfix ‘_spec.rb’
Example of CUSTOM_TEST_NAME:


test file: INTEGRATION_TESTS_DIRECTORY/test1_spec.rb
CUSTOM_TEST_NAME: test1

PROVIDER_ARGUMENT is a ruby array filled with no more that 3 different provider names:

  • DOCKER
  • LIBVIRT
  • PPC

Example of PROVIDER_ARGUMENT:


[DOCKER, LIBVIRT]

Depending on PROVIDER_ARGUMENT, for each provider would be created clone