-
-
Notifications
You must be signed in to change notification settings - Fork 686
/
running_tests.rst
136 lines (99 loc) · 4.94 KB
/
running_tests.rst
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
.. _blenderbim/running_tests:
Running tests
=============
The BlenderBIM Add-on has three layers of tests for each of its three technology
layers:
1. **Core tests**: abstract domain logic unit tests agnostic of Blender
2. **Tool tests**: low-level concrete unit tests dependent on Blender
3. **BIM tests**: high-level integration UI and smoke tests dependent on Blender
These tests use ``pytest`` as the test framework and runner, so install it:
.. code-block:: bash
$ pip install pytest
All development is expected to use test driven development, and so we expect
test coverage to be 100% where it is technically possible to test.
When running tests, Makefile targets are provided for convenience so you can
type in a simple command without knowing the internals. This means you can run
tests by using the ``make`` command.
Because the BlenderBIM Add-on depends on IfcOpenShell, it is advised to also run
tests for IfcOpenShell and its Python bindings, which is not covered in this
document.
Core tests
----------
The core layer tests are pure Python unit tests with no dependencies on Blender
or other modules. They are designed to be fast and easy to run as they test
purely abstract domain logic.
Although they are vanilla Python tests, they do not use the Python Mock module.
Instead, a lightweight ``Prophecy`` mocker class is used, which allows tests to
be written in a highly concise, expressive manner. For those coming from a
BDD background in Ruby's RSpec, PHP's PHPSpec, and PHP's Prophecy, this is very
similar.
.. code-block:: bash
$ cd src/blenderbim/
$ make test-core
# If you're on Windows, and don't want to use make, use:
$ pytest -p no:pytest-blender test/core
Tool tests
----------
The tool layer tests actual concrete functions. You will need to install the
following dependencies:
* pytest-blender, accessible to your system's Python
* Blender executable, accessible to pytest-blender on your system's Python
(e.g. through the ``blender`` command in your path)
.. code-block:: bash
$ pip install pytest-blender
# Check that "Blender" is in your system's path
$ blender
On Windows, you can add Blender to the system path by doing:
1. Open the start menu and launch **Control Panel** > **System** > **Edit the
system environment variables**
2. In the **System Properties** window, under the **Advanced** tab press
**Environment Variables**. This will open a dialog showing a list of all your
variables.
3. In the **System Variables** section select the entry named **Path**, and
press **Edit...**. This will open a new dialog showing all the directories
stored in the **Path** variable.
4. Press **New** and browse to the directory where your **blender.exe** is
located, such as in ``C:\Program Files\Blender Foundation\Blender 3.2``.
In addition, you will need to install these dependencies for Blender:
* pytest, accessible to your Blender Python
* pytest-bdd, accessible to your Blender Python
You can install the dependencies by running the ``setup_pytest.py`` script in
Blender:
1. Launch Blender
2. Load ``src/blenderbim/scripts/setup_pytest.py`` in the Blender text editor
3. Run the script by pressing ``Text > Run Script``.
4. Check the Blender console for any errors or success messages.
.. warning::
The ``scripts/setup_pytest.py`` may not work for all operating systems and
installation environments. In this case, you may be required to install the
dependencies manually.
Please be aware that some Blender may come packaged with its own Python,
which may be separate to the Python installation on your system. Be sure to
install the dependencies to the correct Python environment.
Then, run the tests. This will launch Blender headlessly and check the behaviour
of all concrete functions.
.. code-block:: bash
$ cd src/blenderbim/
$ make test-tool # Test everything
$ make test-tool MODULE=foo # Only test a single module
# If you're on Windows, and don't want to use make, use:
$ pytest test/tool # Test everything
$ pytest test/tool/test_foo.py # Only test a single module
BlenderBIM Add-on tests
-----------------------
The BIM layer acts as a full integration test. It is not possible to fully test
the UI, as we cannot reliably emit interface signals, nor read the interface as
a DOM of sorts. The best we can do is to call Blender operators as a smoke test,
and also check simple property and scene changes.
Before running these tests, follow the instructions for running tool tests
above.
You will also need to enable the **Sun Position** add-on, as it is required to
test georeferencing features: ``Edit > Preferences > Add-ons`` and enable
**Lighting: Sun Position**.
.. code-block:: bash
$ cd src/blenderbim/
$ make test-bim # Test everything
$ make test-bim MODULE=foo # Only test a single module
# If you're on Windows, and don't want to use make, use:
$ pytest test/bim # Test everything
$ pytest test/bim -m "foo" ./ --maxfail=1 # Only test a single module