-
Notifications
You must be signed in to change notification settings - Fork 5
How to create unit test
Here you find information how to create unit test, where to store unit test
Unit tests are kept in MDBCI_DIRECTORY/spec/unit folder.
Create ruby file like this: CUSTOM_TEST_NAME_spec.rb in unit tests folder
Unit test example: https://github.com/OSLL/mdbci/blob/integration/spec/unit/6640_sudo_exit_code_spec.rb
In that test we used some preparation:
before :all do
$out = Out.new
$session = Session.new
$session.mdbciDir = Dir.pwd
$exception_handler = ExceptionHandler.new
boxesPath = './BOXES'
$session.boxes = BoxesManager.new boxesPath
reposPath = './repo.d'
$session.repos = RepoManager.new reposPath
end
This, often, is enough to call some function of Session class.
If test non parametrized add next line to file MDBCI_DIRECTORY/spec/unit_tasks.rb like:
namespace :run_unit do
...
task :task_CUSTOM_TEST_NAME do |t| RakeTaskManager.new(t).run_unit(PROVIDER_ARGUMENT) end
...
end
If test parametrized add next line to file MDBCI_DIRECTORY/spec/unit_parametrized_tasks.rb:
namespace :run_unit_parametrized do
...
task :task_CUSTOM_TEST_NAME do |t| RakeTaskManager.new(t).run_unit_parametrized(PROVIDER_ARGUMENT) end
...
end
CUSTOM_TEST_NAME is a name of file with test from unit tests directory but without postfix ‘_spec.rb’
Example of CUSTOM_TEST_NAME:
test file: UNIT_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