How do I use matlab.uitest.TestCase to open my app once and perform multple function tests?

3 次查看(过去 30 天)
I'm using matlab.uitest.TestCase to test my app. I'm looking for a way to launch my app only once and then perform a variety of tests defined under methods (Test)

采纳的回答

Steven Lord
Steven Lord 2023-1-26
You could do this by opening your app in a TestClassSetup method and storing a handle to it in a property of your test class, but this could lead to your tests violating the "Keep Tests Independent" principle.
Suppose you had two buttons, A and B. You want to unit test both buttons. So you write one test method named testA that clicks button A and another named testB that clicks button B. But the code that executes when you click button A disables button B. Depending on the order in which testA and testB run and whether or not they restore the state of the app back to how it was before they ran, testB may or may not fail. And if you tried to reproduce the failure (to investigate the root cause) by just running testB it would pass.
Heisenbugs are highly annoying to investigate.
  7 个评论
Steven Lord
Steven Lord 2023-1-27
This documentation page has an example of using shared test fixtures. The example runs two tests that each need to have a certain directory on the MATLAB search path. Instead of having each test add the directory to the path and restore the path afterwards they use a shared test fixture to add it to the path before either test runs and restore the path after both tests have run.
Another example where you might want to use a shared test fixture is to create or read a large data set to be used in multiple test files. Imagine the example on this documentation page but with a large matrix instead of a short user name.
You could have a shared test fixture that opens your app for multiple test files to use, but remember to Keep Tests Independent.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Testing Frameworks 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by