How do I teardown fixture while using a TestCase obj in interactive mode?
이전 댓글 표시
I found matlab.unittest.TestCase.forInteractiveUse extremely useful for development and debugging of test cases written for matlab.unittest.TestCase.
But if I use applyFixture method of a test method of such a TestCase obj that is in interattive mode by forInteractiveUse, how do I teardown the fixture? Simply deleting the TestCase won't does it, will it?
For example, say I have a TestCase class like this:
classdef testcase1 < matlab.unittest.TestCase
methods (Test)
function testmethod1(testCase)
testCase.applyFixture(thisfixture);
% blah, blah, blah
end
end
end
Then, for development, I excute the following command:
testCase = testcase1; testCase.forInteractiveUse;
Then I can evaluate anything within the TestCase just like a script. However, in case a test method uses matlab.unittest.fixtures.Fixture for setup, I would like to do this:
testCase.applyFixture(fixtureforthis);
Then I can comfortablly evaluate/debug the rest of code in the test method. My question is how can I get out of this state. How can I invoke teardown method of the fixture thisfixture while in interactive mode?
채택된 답변
추가 답변 (2개)
Andy Campbell
2015년 4월 22일
Hello Kouichi,
Yes applyFixture ties the fixture teardown step to the lifecycle of the testCase upon which it is applied, so once the testCase is deleted the fixture will indeed get torn down as you have seen.
However, this line confuses me:
testCase = testcase1; testCase.forInteractiveUse;
What that is doing is creating a new instance of the testcase1 class which will not inform you of failures as you play with it on the command line. For example, testCase.verifyEqual(1,0) will not show you any diagnostics that desrcibe that 1 is not equal to 0.
Then, testCase.forInteractiveUse calls a static method (not using the testCase instance you created, it is equivalent to matlab.unittest.TEstCase.forInteractiveUse) that creates a new testCase instance which isn't even of type testcase1, but that has the correct configuration applied to show you diagnostics at the command line. It seems perhaps you are looking for something that neither the first line nor the second is really giving you. Can you explain more about what you need?
Thanks, Andy
Kouichi Nakamura
2015년 4월 23일
댓글 수: 3
Andy Campbell
2015년 4월 24일
편집: Andy Campbell
2015년 4월 24일
Thanks for the info Kouichi.
We can look into providing a way for the interactive listeners to be added to your sublcass of testcase so that you can interact with your test case and its methods and properties while still having all of the interactive output provided to the command window.
In 14a, you have the interactive behavior when just constructing the object, but that is problematic and is very likley to change in a future release. For now, you don't need to call forInteractiveUse at all for your case and you can just construct the isntance. However, in the future you may need to use a different function or method call to create an instance of MyClass that includes this interactive behavior.
Thanks, Andy
Kouichi Nakamura
2015년 5월 13일
Andy Campbell
2015년 10월 19일
편집: Andy Campbell
2015년 10월 19일
Note, as of R2015b you can get interactive testCase instances for your own subclasses by passing the desired meta.class as an input argument to the forInteractiveUse static method:
tc = matlab.unittest.TestCase.forInteractiveUse(?MyClass)
This allows you to have your interactive listeners placed on your own sublcass of TestCase so that you can also call any helper methods or properties of your TestCase class.
Enjoy! Andy
카테고리
도움말 센터 및 File Exchange에서 Write Unit Tests에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!