![]() ![]() PrivateFcn = get_private_fcn(privateDir,'sub') %# Call get_private_fcnĪssertElementsAlmostEqual(privateFcn(), 123) %# Apply your test PrivateDir = '.\project_root\code\private' %# The path to the private PrivateFcn = str2func(fcnName) %# Get a function handleĬd(oldDir) %# Change back to the original directoryĪnd you would use this function in testsub as follows: function testsub() OldDir = cd(privateDir) %# Change to the private directory You could even put these steps in a separate helper function for your unit testing, like so: function privateFcn = get_private_fcn(privateDir,fcnName) One solution is to navigate to the private directory from within testsub, get a function handle to the private function you want using STR2FUNC, then navigate back to do the testing using that function handle. Unfortunately the testing framework navigates to the directory containing the tests as soon as you call run. In theory I could call, e.g., cd(privateDirectory) The idea of navigating to the private directory has a problem. What is the best way to get access to test the private functions? I could possibly put a function in the code dir that retrieves handles to all the private functions but this seems hacky. Private directories aren't allowed on the matlab path so that isn't an option. ![]() You should see an error saying that sub is undefined. Now navigate to the test dir and call runtests. In the test dir place a function function testsub() In the private dir place a function function y = sub() In the code directory place a function function y = main() In code, create a subdirectory named private so you directory tree looks like project_root ![]() I'd like to be able to directly call some functions that are contained in a private directory.Ĭreate yourself a project directory with two folders code and test. I'm using MATLAB xUnit to test some code. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |