howto_add_unittests.txt
1.46 KB
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
Howto: Add unittests
--------------------
Note: The following are just guidelines to help inexperienced users create unit
tests. The python unittest library (see
https://docs.python.org/2/library/unittest.html) offers much more flexibility
than described here.
For helping python's unittest to discover your tests, do the following:
* create a subdirectory within oletools/tests/
- The directory name must be a valid python package name,
so must not include '-', for example
- e.g. oletools/tests/my_feature
* Create a __init__.py inside that directory
- can be empty but must be there
* Copy the unittest_template.py into your test directory
* Rename your copy of the template to fit its purpose
- file name must start with 'test' and end with '.py'
- e.g. oletools/tests/my_feature/test_bla.py
* Create python code inside that directory
- classes names must start with Test and must be subclasses
of Unittest.TestCase
- test functions inside your test cases must start with test_
- see unittest_template.py for examples
* If your unit test requires test files, put them into a subdir
of oletools/tests/test-data with some name that clarifies what
tests it belongs to
- e.g. oletools/tests/test-data/my_feature/example.doc
- Do not add files with actual evil malware macros! Only harmless
test data!
* Test that unittests work by running from the oletools base dir:
python -m unittest discover -v
* Re-test with python2 and python3 (if possible)