Change-Id: I246ea441a9c2e2039ce32b73773d43f58971dfe4 Implements: blueprint nailgun-code-testing-improvements
18 KiB
Nailgun code testing improvements
https://blueprints.launchpad.net/fuel/+spec/nailgun-code-testing-improvements
Current unit and integration tests needs improvement and should follow a single code testing policy.
Problem description
Terms
Unit testing is a software testing method by which individual units of source code are tested to determine if they are fit for use. The goal of unit testing is to isolate each part of the program and show that the individual parts are correct1.
Integration testing is the phase in software testing in which individual software modules are combined and tested as a group2.
Functional testing is a quality assurance (QA) process and a type of black-box testing that bases its test cases on the specifications of the software component under test. Functions are tested by feeding them input and examining the output3.
Since functional testing is a part of QA process we don't consider its usage in the scope of this document.
Problems
- The project needs to have a policy which describes tests writing rules.
- Not all classes and functions are covered with tests.
- There's no test coverage measurement and, accordingly, no lower bound for test coverage.
- Unit and functional tests are not arranged properly and do not correspond with their purposes.
- Skipped tests lead to lack of coverage.
- Tests duplicate each other.
- Some helper classes and functions don't have descriptive names.
nailgun.db.syncdb()
is used for the test database creation. It runs all migrations one-by-one which is pretty slow.
Current test coverage
Test coverage procedure is performed using py.test-cov utility by running the following command:
py.test --cov-config .coveragerc --cov nailgun nailgun/test/
.coveragerc
file lists files and directories are not
taken into account when calculating code coverage:
[run]
omit =
nailgun/test/*
nailgun/openstack/common/*
nailgun/unit_test*
where nailgun/tests/
and
nailgun/unit_test.py
contain the tests itself,
nailgun/openstack/common
is a part of
oslo-incubator
.
Here's the report generated on December 23, 2014:
Name | Stmts | Miss | Cover |
---|---|---|---|
nailgun/__init__ |
|
|
|
nailgun/api/__init__ |
|
|
|
nailgun/api/v1/__init__ |
|
|
|
nailgun/api/v1/handlers/__init__ |
|
|
|
nailgun/api/v1/handlers/assignment |
|
|
|
nailgun/api/v1/handlers/base |
|
|
|
nailgun/api/v1/handlers/capacity |
|
|
|
nailgun/api/v1/handlers/cluster |
|
|
|
nailgun/api/v1/handlers/disks |
|
|
|
nailgun/api/v1/handlers/logs |
|
|
|
nailgun/api/v1/handlers/master_node_settings |
|
|
|
nailgun/api/v1/handlers/network_configuration |
|
|
|
nailgun/api/v1/handlers/node |
|
|
|
nailgun/api/v1/handlers/node_group |
|
|
|
nailgun/api/v1/handlers/notifications |
|
|
|
nailgun/api/v1/handlers/orchestrator |
|
|
|
nailgun/api/v1/handlers/plugin |
|
|
|
nailgun/api/v1/handlers/registration |
|
|
|
nailgun/api/v1/handlers/release |
|
|
|
nailgun/api/v1/handlers/removed |
|
|
|
nailgun/api/v1/handlers/tasks |
|
|
|
nailgun/api/v1/handlers/version |
|
|
|
nailgun/api/v1/urls |
|
|
|
nailgun/api/v1/validators/__init__ |
|
|
|
nailgun/api/v1/validators/assignment |
|
|
|
nailgun/api/v1/validators/base |
|
|
|
nailgun/api/v1/validators/cluster |
|
|
|
nailgun/api/v1/validators/json_schema/__init__ |
|
|
|
nailgun/api/v1/validators/json_schema/assignment |
|
|
|
nailgun/api/v1/validators/json_schema/base_types |
|
|
|
nailgun/api/v1/validators/json_schema/cluster |
|
|
|
nailgun/api/v1/validators/json_schema/disks |
|
|
|
nailgun/api/v1/validators/json_schema/networks |
|
|
|
nailgun/api/v1/validators/json_schema/node |
|
|
|
nailgun/api/v1/validators/json_schema/plugin |
|
|
|
nailgun/api/v1/validators/json_schema/release |
|
|
|
nailgun/api/v1/validators/master_node_settings |
|
|
|
nailgun/api/v1/validators/network |
|
|
|
nailgun/api/v1/validators/node |
|
|
|
nailgun/api/v1/validators/node_group |
|
|
|
nailgun/api/v1/validators/notification |
|
|
|
nailgun/api/v1/validators/plugin |
|
|
|
nailgun/api/v1/validators/release |
|
|
|
nailgun/api/v1/validators/task |
|
|
|
nailgun/app |
|
|
|
nailgun/assassin/__init__ |
|
|
|
nailgun/assassin/assassind |
|
|
|
nailgun/autoapidoc |
|
|
|
nailgun/consts |
|
|
|
nailgun/db/__init__ |
|
|
|
nailgun/db/deadlock_detector |
|
|
|
nailgun/db/migration/__init__ |
|
|
|
nailgun/db/migration/alembic_migrations/env |
|
|
|
nailgun/db/migration/alembic_migrations/versions/fuel_5_0 |
|
|
|
nailgun/db/migration/alembic_migrations/versions/fuel_5_1 |
|
|
|
nailgun/db/migration/alembic_migrations/versions/fuel_6_0 |
|
|
|
nailgun/db/sqlalchemy/__init__ |
|
|
|
nailgun/db/sqlalchemy/fixman |
|
|
|
nailgun/db/sqlalchemy/models/__init__ |
|
|
|
nailgun/db/sqlalchemy/models/action_logs |
|
|
|
nailgun/db/sqlalchemy/models/base |
|
|
|
nailgun/db/sqlalchemy/models/cluster |
|
|
|
nailgun/db/sqlalchemy/models/fields |
|
|
|
nailgun/db/sqlalchemy/models/master_node_settings |
|
|
|
nailgun/db/sqlalchemy/models/network |
|
|
|
nailgun/db/sqlalchemy/models/network_config |
|
|
|
nailgun/db/sqlalchemy/models/node |
|
|
|
nailgun/db/sqlalchemy/models/notification |
|
|
|
nailgun/db/sqlalchemy/models/plugins |
|
|
|
nailgun/db/sqlalchemy/models/release |
|
|
|
nailgun/db/sqlalchemy/models/task |
|
|
|
nailgun/db/sqlalchemy/utils |
|
|
|
nailgun/errors/__init__ |
|
|
|
nailgun/errors/base |
|
|
|
nailgun/expression/__init__ |
|
|
|
nailgun/expression/expression_parser |
|
|
|
nailgun/expression/objects |
|
|
|
nailgun/fake_keystone/__init__ |
|
|
|
nailgun/fake_keystone/handlers |
|
|
|
nailgun/fake_keystone/urls |
|
|
|
nailgun/fixtures/__init__ |
|
|
|
nailgun/fsm/__init__ |
|
|
|
nailgun/fsm/state_list |
|
|
|
nailgun/logger |
|
|
|
nailgun/middleware/__init__ |
|
|
|
nailgun/middleware/connection_monitor |
|
|
|
nailgun/middleware/http_method_override |
|
|
|
nailgun/middleware/keystone |
|
|
|
nailgun/middleware/static |
|
|
|
nailgun/middleware/utils |
|
|
|
nailgun/network/__init__ |
|
|
|
nailgun/network/checker |
|
|
|
nailgun/network/manager |
|
|
|
nailgun/network/neutron |
|
|
|
nailgun/network/nova_network |
|
|
|
nailgun/network/utils |
|
|
|
nailgun/notifier |
|
|
|
nailgun/objects/__init__ |
|
|
|
nailgun/objects/action_log |
|
|
|
nailgun/objects/base |
|
|
|
nailgun/objects/capacity |
|
|
|
nailgun/objects/cluster |
|
|
|
nailgun/objects/master_node_settings |
|
|
|
nailgun/objects/node |
|
|
|
nailgun/objects/node_group |
|
|
|
nailgun/objects/notification |
|
|
|
nailgun/objects/plugin |
|
|
|
nailgun/objects/release |
|
|
|
nailgun/objects/serializers/__init__ |
|
|
|
nailgun/objects/serializers/action_log |
|
|
|
nailgun/objects/serializers/base |
|
|
|
nailgun/objects/serializers/cluster |
|
|
|
nailgun/objects/serializers/master_node_settings |
|
|
|
nailgun/objects/serializers/network_configuration |
|
|
|
nailgun/objects/serializers/node |
|
|
|
nailgun/objects/serializers/node_group |
|
|
|
nailgun/objects/serializers/notification |
|
|
|
nailgun/objects/serializers/plugin |
|
|
|
nailgun/objects/serializers/release |
|
|
|
nailgun/objects/serializers/task |
|
|
|
nailgun/objects/task |
|
|
|
nailgun/openstack/__init__ |
|
|
|
nailgun/orchestrator/__init__ |
|
|
|
nailgun/orchestrator/deployment_serializers |
|
|
|
nailgun/orchestrator/plugins_serializers |
|
|
|
nailgun/orchestrator/priority_serializers |
|
|
|
nailgun/orchestrator/provisioning_serializers |
|
|
|
nailgun/plugins/__init__ |
|
|
|
nailgun/plugins/attr_plugin |
|
|
|
nailgun/plugins/manager |
|
|
|
nailgun/rpc/__init__ |
|
|
|
nailgun/rpc/receiver |
|
|
|
nailgun/rpc/receiverd |
|
|
|
nailgun/rpc/threaded |
|
|
|
nailgun/rpc/utils |
|
|
|
nailgun/settings |
|
|
|
nailgun/statistics/__init__ |
|
|
|
nailgun/statistics/installation_info |
|
|
|
nailgun/statistics/openstack_info_collector |
|
|
|
nailgun/statistics/params_white_lists |
|
|
|
nailgun/statistics/statsenderd |
|
|
|
nailgun/task/__init__ |
|
|
|
nailgun/task/fake |
|
|
|
nailgun/task/helpers |
|
|
|
nailgun/task/manager |
|
|
|
nailgun/task/task |
|
|
|
nailgun/urls |
|
|
|
nailgun/utils/__init__ |
|
|
|
nailgun/utils/migration |
|
|
|
nailgun/utils/zabbix |
|
|
|
nailgun/volumes/__init__ |
|
|
|
nailgun/volumes/manager |
|
|
|
nailgun/webui/__init__ |
|
|
|
nailgun/webui/handlers |
|
|
|
nailgun/webui/urls |
|
|
|
nailgun/wsgi |
|
|
|
---------------------------------------------------------- | ------ | ---- | ----- |
TOTAL |
|
1453 |
|
Proposed change
nailgun
project needs improvements in code testing as
follows:
Create a policy which describes:
- Tests creation technique.
- Test categorization (integration/unit/performance) and approaches of testing different Nailgun modules.
Fuel project already has a policy scaffold on wiki page4. It needs to be updated and placed to official development documentation source5.
All the classes and functions should be covered with tests. A test coverage percentage should be more than 90%.
Some of classes and functions should be covered with integration as well as unit tests. This is left at the discretion of the developer.
Fix 'skipped' tests.
Remove duplicated tests.
Mimic Nailgun module structure in unit tests.
Rename <Environment> class to a more descriptive <EnvironmentManager>6.
Remove hardcoded <clusters>, <releases> and <nodes> attributes from <Environment> class. Let's use parameters instead7. These parameters will provide additional flexibility in writing tests
Remove
nailgun.db.syncdb()
logic fromrun_tests.sh
. Add database schema creation to the test base class by means ofBase.metadata.create_all
.Add tests for Alembic migrations8.
Considering usage of custom fixture provider is beyond the scope of this document.
Review and refactor tests as exposed in the code testing policy.
Alternatives
None
Data model impact
None
REST API impact
None
Upgrade impact
None
Security impact
None
Notifications impact
None
Other end user impact
None
Performance Impact
None
Other deployer impact
None
Developer impact
Developers have to follow the code testing policy9.
Implementation
Assignee(s)
- Primary assignee:
-
ivankliuk
- Other contributors:
-
fuel-python
Work Items
None
Dependencies
None
Testing
This document describes testing itself.
Documentation Impact
Nailgun development documentation10 is updated with the code testing policy 11 by primary assignee.