77
88This should tell you which tests pass or fail.
99
10+ ## code coverage
11+
1012The following command would give more info and will give you HTML output in a ` coverage_html ` folder
1113showing you which lines of code is or is not checked by your test suite.
1214
@@ -18,6 +20,78 @@ success = moxunit_runtests(pwd, ... % the path where the tests are
1820 '-cover_xml_file','coverage.xml', ...
1921 '-cover_html_dir','coverage_html');
2022```
23+ This will return a clear underestimation of the code coverage as the the code in dependencies in the ` lib ` folder
24+ are also included in this report.
25+
26+ If you want to get a slightly more accurate estimate you should run the following.
27+
28+ I have not been able to find a way to exclude certain files without breaking some tests.
29+
30+ ``` matlab
31+ coverage = mocov( ...
32+ '-expression', 'moxunit_runtests()', ...
33+ '-verbose', ...
34+ '-cover', fullfile(pwd, '..'), ...
35+ '-cover_exclude', '*jsonread.m', ...
36+ '-cover_exclude', '*json*code.m', ...
37+ '-cover_exclude', '*Contents.m', ...
38+ '-cover_exclude', '*report.m', ...
39+ '-cover_exclude', '*layout.m', ...
40+ '-cover_exclude', '*query.m', ...
41+ '-cover_exclude', '*private*', ...
42+ '-cover_exclude', '*util*', ...
43+ '-cover_exclude', '*Tests*', ...
44+ '-cover_exclude', '*tests*', ...
45+ '-cover_exclude', '*test_*', ...
46+ '-cover_xml_file','coverage.xml', ...
47+ '-cover_html_dir','coverage_html')
48+ ```
49+
50+
51+ ## Adding more tests
52+
53+ You can use the following function template to write more tests.
54+
55+
56+ ``` matlab
57+ function test_suite = test_functionToTest()
58+ % This top function is necessary for mox unit to run tests.
59+ % DO NOT CHANGE IT except to adapt the name of the function.
60+ try % assignment of 'localfunctions' is necessary in Matlab >= 2016
61+ test_functions = localfunctions(); %#ok<*NASGU>
62+ catch % no problem; early Matlab versions can use initTestSuite fine
63+ end
64+ initTestSuite;
65+ end
2166
67+ function test_functionToTestBasic()
2268
69+ %% set up
70+
71+
72+ %% data to test against
73+
74+
75+ %% test
76+ % assertTrue( );
77+ % assertFalse( );
78+ % assertEqual( );
79+
80+ end
81+
82+ function test_functionToTestUseCase1()
83+
84+ %% set up
85+
86+
87+ %% data to test against
88+
89+
90+ %% test
91+ % assertTrue( );
92+ % assertFalse( );
93+ % assertEqual( );
94+
95+ end
96+ ```
2397
0 commit comments