Is there an easy way to build a test suite from all tests in a folder containing multiple packages?

11 次查看(过去 30 天)
I have a non-package directory, containing several packages. Each package may contain subpackages. The packages have class-based unit tests. I can run all the tests for a given package by calling
runtests('mypackage1', "IncludeSubpackages", true)
Is there an easy way to run all tests for all packages?
If I call
runtests(pwd, "IncludeSubfolders", true, "IncludeSubpackages", true)
No tests are run.

采纳的回答

Andy Campbell
Andy Campbell 2019-12-3
编辑:Andy Campbell 2019-12-3
Hi Brian,
I definitely endorse Sean's suggestion to use projects. That said, this is good feedback since it seems you expected IncludeSubfolders to just work in this case. There are reasons for the current behavior, but we can take this feedback to the development team.
In the meantime, if you don't use Sean;s suggestion of putting it into a project, you should be able to create your suite as follows:
import matlab.unittest.TestSuite;
w = what(pwd);
suiteCell = cellfun(@(p) TestSuite.fromPackage(p, 'IncludingSubpackages',true), w.packages, 'UniformOutput', false)
suite = [suiteCell{:}];
run(suite);
Hope that helps!

更多回答(1 个)

Sean de Wolski
Sean de Wolski 2019-12-2
编辑:Sean de Wolski 2019-12-2
Have you considered adopting projects? I'd recommend it (for most things and especially for this use case) then you can just create the TestSuite from all files in the project.
Otherwise, shy of manually appending multiple TestSuites I don't know a way. My team usually keeps all tests as classes optionally in subppackages of a parent +test package so it's obvious it's a test.
  2 个评论
TallBrian
TallBrian 2019-12-6
@seandewolski I looked into projects. I have a couple of questions.
1) Is it possible to separate functions into namespaces similar to package functionality in projects?
2) Can you have projects of projects?
3) Is it possible to generate a test suite from both the root level of a project (yes, you have linked the instructions) as well a subfolder of the project?
I would like to have some structure where I can run all tests for everything easily and then also just run tests for one subgroup easily. Is there a best practice for this?
thank you.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Create and Run MATLAB Tests 的更多信息

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by