Integration Test Design¶
Test Template¶
A test should be written for every feature.
Create a new python file to contain the feature test code.
For example, if the feature concerns x_feature, the test case would be stored in
testframework/test/../../test_x_feature.py.Derive the test class from
test.SingleNifand name itTestXFeature.test.SingleNifis designed upon the template pattern and takes care of all execution, loading of files and clean up.Note
A template for a test class is available in
testframework/test/template.py.Each test needs to overwrite the following methods from
test.SingleNif:The
n_create_data()used to create the physical .nifThe
n_check_data()used to test the data of physical .nifThe
b_create_data()used to mimic how the user would create the objects.The
b_check_data()check Blender data, used to check before export and after import.
These methods are intended to be delegate function, calling external methods in either n_gen_xxxx or b_gen_xxxx files.
Note
We move all the code to external modules for code reuse code to avoid importing other tests, avoiding tests to be re-run unnecessarily.
Test Implementation¶
Each test has two paths of execution one importing/export a python generated nif, the other exporting/importing a nif created by mimicking how a user would create it.
Each test can be comprised of multiple required features and a lego block-building approach should be taken to building the nifs.
Recreate the nif using python:
Create a nif (say in nifskope, or with the old Blender nifscripts).
Take care to make the file as simple as possible.
Use PyFFI’s
dump_pythonspell to convert it to python code.The
n_create_data()method of the class will call the methods fromn_gen_x_featuremodule to construct the physical nif.It may be required to call other reusable functions from other tests. Reusable functions should be created from the dump_python and stored in
testframework/test/../../n_gen_x_feature.py.Write code to test the desired features of the physical.
The
n_check_data()method will call the methods fromn_gen_x_featuremodule to check the nif data.
Recreate the feature within Blender, using user functions:
Write Python code which recreates the corresponding data in the Blender scene in
testframework/test/../../b_gen_x_feature.Where possible make the test case as simple as possible.
For instance, use primitives readily available in Blender. This code goes in the
b_create_data()method of the test class.Document the feature in
docs/features/x_feature.rstas you writeb_create_data():Explain what the user has to do in Blender in order to export the desired data, and wherein Blender the data ends up during import.
Write Python code which tests the Blender scene against the desired feature:
b_check_data()method of the test class.
Implement the feature in the import and export plugin, until the regression test passes.
That’s it!
Execution Order¶
The tests will run like this:
User Export¶
b_create_data()to create the scene, saved totest/autoblend/../../x_feature_userver.blendb_check_data()to check it before exportExport the nif to
`test/nif/../../x_feature_export_pycode.nifn_check_data()to check exported nif.
User Import¶
import the exported nif, saved to
test/autoblend/../../x_feature_userver_reimport.blendb_check_data()tests the imported scene.
If the above tests run, then we are in pretty good shape as we can verify import and export work in isolation
Python generated Import / Export¶
Starts by
n_create_data()creating a physical niftest/nif/../../x_feature_py_code.nif.n_check_data()is called to ensure nif is correct before importing.Nif is imported into Blender, the scene is saved to
test/autoblend/../../x_feature_pycode_import.blendb_check_data()is called on imported scene to verify scene data.Nif is exported to
test/nif/../../x_feature_export_pycode.nifn_check_data()on exported nif to verify nif data.
This ensures data integrity both at Blender level and at nif level.