diff --git a/tests/howto_add_unittests.txt b/tests/howto_add_unittests.txt new file mode 100644 index 0000000..3178741 --- /dev/null +++ b/tests/howto_add_unittests.txt @@ -0,0 +1,37 @@ +Howto: Add unittests +-------------------- + +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) diff --git a/tests/unittest_template.py b/tests/unittest_template.py new file mode 100644 index 0000000..a5c2cb6 --- /dev/null +++ b/tests/unittest_template.py @@ -0,0 +1,37 @@ +""" Test my new feature + +Some more info if you want + +Should work with python2 and python3! +""" + +import unittest + +# if you need data from oletools/test-data/DIR/, uncomment these lines: +#from os.path import join, dirname, normpath +#Directory with test data, independent of current working directory +#DATA_DIR = normpath(join(dirname(__file__), '..', 'test-data', 'DIR')) + + +class TestMyFeature(unittest.TestCase): + """ Tests my cool new feature """ + + def test_this(self): + """ check that this works """ + pass # your code here + + def test_that(self): + """ check that that also works """ + pass # your code here + + def helper_function(self, filename): + """ to be called from other test functions to avoid copy-and-paste + + this is not called by unittest directly, only from your functions """ + pass # your code here + # e.g.: msodde.main(join(DATA_DIR, filename)) + + +# just in case somebody calls this file as a script +if __name__ == '__main__': + unittest.main()