Creating MATLAB tests in separate folder/module

5 ビュー (過去 30 日間)
Andrew Hodgson
Andrew Hodgson 2021 年 12 月 7 日
コメント済み: Andrew Hodgson 2021 年 12 月 7 日
I would like to store all my tests in a seperate tests folder within my workspace. The intention of this is to keep the code base simpler and to allow me to use matlab.unittest.TestSuite.fromFolder to create a test suite of all the tests in this directory which can be run in one command.
For example
/
|- tests/
|- testFunctionOne.m
|- testFunctionTwo.m
| functionOne.m
| functionTwo.m
I'm coming from a Python background and this is quite common there. The Python Unittests module searches through a module for all tests and runs them.
When I try this in MATLAB this creates an error as the tests cannot find the functions located in the root directory. This makes sense becasue they're not on the search path when running functions from the tests directory. I don't want to dwell on Python, but this also happens there too. The solution is to add the root directory to the PYTHONPATH variable.
My questions are as follows:
  1. Is it common to locate the tests seperatly from the source code in MATLAB?
  2. What is the best way to add the root directory of my project to the search path of the tests?
  3. Is there another better best practice way of placing all tests outside of the root directory that I'm not aware off?

採用された回答

Yongjian Feng
Yongjian Feng 2021 年 12 月 7 日
編集済み: Yongjian Feng 2021 年 12 月 7 日
Use
addpath("your_root_path")
  3 件のコメント
Yongjian Feng
Yongjian Feng 2021 年 12 月 7 日
You just need to add it once. The matlab path is global. Once added, all will get it.
Andrew Hodgson
Andrew Hodgson 2021 年 12 月 7 日
Brillient, thank you.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

タグ

製品


リリース

R2016b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by