Parameters for Matlab.unittest.TestCase

4 ビュー (過去 30 日間)
Chris
Chris 2015 年 1 月 16 日
回答済み: Ricardo Krause 2019 年 2 月 21 日
I would like to use the framework of TestCase/TestSuite/TestRunner. I want to do the same tests for different test cases. For actually implementing the tests I simple wrote a class derived from "TestCase" where the "methods (Test)" holds the implementation. I am instancing the TestSuite by "fromFolder" where my TestCase-class is located in order to be able to use it for different test cases with the same file structure. That works out fine.
Now I have to problem of transferring parameters to the TestCase-class in order to be able to use them in the setup process, i.e. different setup parameters for the different test cases.
The only solution I could come up with is writing control file to be read in the ClassSetupMethod - but that's not favourable in this situation. Is there a possibility of passing parameters on to the actual TestCase used in the TestRunner, e.g. when creating the instance of the TestCase? I mean online, i.e. different parameters for every run of the TestSuite, and not fixed Parameters like when using "properties (ClassSetupParameter)".
PS: I am using R2013a.
  2 件のコメント
Andy Campbell
Andy Campbell 2015 年 1 月 16 日
Couple questions. How many parameters are we talking about? Are the parameters known ahead of time or are they "dynamic" in some way? Also, is this for production use cases or for simple experimental cases?
Chris
Chris 2015 年 1 月 21 日
There are a limited number of parameters (about 3 to 5) but the parameters are dynamic and not known in advance. Since this should be used for daily overnight tests I have to find an automated way to deal with changes.

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

回答 (2 件)

David Hruska
David Hruska 2015 年 2 月 10 日
If you have access to R2014a or later, parameterized testing could still be an option. Parameter values are often hard-coded but they need not be. You could, for example, call a local function to determine the parameterization of your test:
classdef exampleTest < matlab.unittest.TestCase
properties (ClassSetupParameter)
Param = getParameterValues;
end
% Reset of the test code
end
function p = getParameterValues
% Determine paramterization
p = <whatever>
end
In this example, the "getParameterValues" function gets called when the class is parsed -- typically the first time you create the suite in a MATLAB session. The function won't get called again (and therefore you won't get a different parameterization) until you clear the class or start a new MATLAB session. If you can live with these limitations, parameterized testing might be worth a look.
  1 件のコメント
Aditya
Aditya 2016 年 11 月 9 日
編集済み: Aditya 2016 年 11 月 9 日
I had a similar issue (using 2016a), in which I wanted to have the parameterization for the test suite to come from external data. I used your suggestion and it seems to work. Great idea.

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


Ricardo Krause
Ricardo Krause 2019 年 2 月 21 日
Hi @all,
in relation to this topic I've been thinking about the use of an IoC container which I like to use for different test cases in same tests.
I tried to setup my container as singleton in the TestRunner, but I struggle to make them available in my test classes.
Has anyone had any experience with this?
BR

カテゴリ

Help Center および File ExchangeExtend Testing Frameworks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by