How can the code tell if a single test is running instead of the whole test class?
4 次查看(过去 30 天)
显示 更早的评论
I'd like to see more output when I run a single test, vs when I run a whole test class or suite.
Almost always, this is because I'm running it several or many times while debugging, launching the single test with the command-return shortcut. This is a different use case from running all the tests in a file, much less all the tests in a suite. You can think of it like raising the log level
Is there a way, either in a test, or in one of the TestClassSetup (setupOnce() or set()) methods that the code can determine this?
PS: The answer seems to be "no."
2 个评论
Steven Lord
2020-5-29
Why do you want to see more output when you run one test method instead of a test class or test suite?
Ideally your test methods should be completely independent of one another. They should neither know nor care whether or not another test method is running in the same test run.
回答(2 个)
Sean de Wolski
2020-5-29
Having the tests needing to know about how they are running is backwards. The tests should always do the same thing - test the code and provide outputs. Plugins added to the TestRunner should decide whether to absorb these outputs or not.
So if you want additional outputs, add plugins to the TestRunner. It may be a custom plugin, it may just be withTextOutput. You could write a few convenience functions to run the test suite with or without test this level of output.
Steven Lord
2020-5-29
If you're running this to debug, I assume you actually want the additional information only when the test fails. If so try matlab.unittest.TestCase.onFailure.
If not, if you want explicit control over the logging level, how are you running the test?
- With runtests? Specify the LoggingLevel or OutputDetail in your runtests call.
- With run on a TestRunner object? Try adding a plugin to the TestRunner as Sean suggested.
- In the Editor or Live Editor? Click the downward facing triangle under Run Tests and change the output detail or logging level.
2 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Run Unit Tests 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!