- Implement the createTestMethodInstance and/or createTestClassInstance method on the plugin in order to get a hold of the TestCase instances passed to the test
- Add listeners to these instances to listen to the possible failure events
- When the events are triggered, the listeners are either passed a QualificationEventData or an ExceptionEventData which contains this information and can be stored away and referenced later.
Info
この質問は閉じられています。 編集または回答するには再度開いてください。
How to create a plugin that stores the exception from a failing test
1 回表示 (過去 30 日間)
古いコメントを表示
Hi,
I am running MATLAB R2014a and I'm running single tests with the command:
result = run(NameOfTestClass, 'NameOfTestMethod')
I can then find out if the test passed or failed by looking at the value of:
result.Passed
and
result.Failed
Is it possible that I can store in the result the reason that the test failed, and the stacktrace?
Would this be via writing a plugin?
Thanks
0 件のコメント
回答 (3 件)
Andy Campbell
2014 年 7 月 7 日
編集済み: Andy Campbell
2014 年 7 月 7 日
Hi Daniel,
There is currently no plugin included with the framework that directly stores this information on its properties. However, this information is accessible if you write your own plugin. What you need to do when writing your plugin is:
Also, it sounds like you really want programmatic access to this information, but just so you are aware you can leverage a different OutputStream to send the textual output from something like the FailureDiagnosticsPlugin. That is you can:
import matlab.unittest.TestSuite;
import matlab.unittest.TestRunner;
import matlab.unittest.plugins.ToFile;
import matlab.unittest.plugins.FailureDiagnosticsPlugin;
suite = TestSuite.fromClass(?NameOfClass);
plugin = FailureDiagnosticsPlugin(ToFile(some_file_on_disk));
runner = TestRunner.withNoPlugins;
runner.addPlugin(plugin);
result = runner.run(suite);
You can also create your own OutputStream such as a stream which just holds all of the output in a property of a class, but it will all be textual information, whereas if you use the listener approach you will be able to access the data as MATLAB objects and data structures.
Hope that helps!
Andy
0 件のコメント
per isakson
2014 年 7 月 6 日
編集済み: per isakson
2014 年 7 月 6 日
2 件のコメント
per isakson
2014 年 7 月 8 日
I still run R2013a and I use
msg_str = evalc('results = run( test_runner, test_suite );');
Andy's words should be final!
Andy Campbell
2017 年 1 月 24 日
This is probably a dup of this question as per isakson points out. Be sure to check there to see some more up to date answers that incorporate new features of the framework, like the DiagnosticsRecordingPlugin.
0 件のコメント
この質問は閉じられています。
参考
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!