- 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!