- 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
Questa domanda è chiusa. Riaprila per modificarla o per rispondere.
How to create a plugin that stores the exception from a failing test
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (3)
Andy Campbell
il 7 Lug 2014
Modificato: Andy Campbell
il 7 Lug 2014
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 Commenti
per isakson
il 6 Lug 2014
Modificato: per isakson
il 6 Lug 2014
2 Commenti
per isakson
il 8 Lug 2014
I still run R2013a and I use
msg_str = evalc('results = run( test_runner, test_suite );');
Andy's words should be final!
Andy Campbell
il 24 Gen 2017
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 Commenti
Questa domanda è chiusa.
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!