AXForum  
Вернуться   AXForum > Microsoft Dynamics AX > DAX Blogs
All
Забыли пароль?
Зарегистрироваться Правила Справка Пользователи Сообщения за день Поиск

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 28.10.2006, 17:43   #1  
Blog bot is offline
Blog bot
Участник
 
25,475 / 846 (79) +++++++
Регистрация: 28.10.2006
Pokluda: SysTest part V.: Test execution (results, runners and listeners)
Источник: http://blogs.msdn.com/dpokluda/archi...Execution.aspx
==============

In the series of previous posts I've covered TestClasses and TestSuites. You should already know how to create a TestClass and how to group your tests in TestSuites. In this post I'll try to cover the test execution environment. Results and Runners


You probably remember the following code: static void RunSimpleTests(Args _args) { SysTestSuite suite = new SysTestSuite(classstr(SimpleTests)); SysTestResult result = new SysTestResult(); ; result.addListener(new SysTestListenerPrint()); suite.run(result); print result.getSummary(); pause; }
This code creates a runtime suite for all test methods from SimpleTests class. The following diagram displays all objects that are interacting during test execution.

SysTestRunner is a new component that is used to glue your test and result object. It takes care of the suite creation as well as the result object creation. The following sample is doing the same thing as the previous one. static void RunSimpleTestsUsingRunner(Args _args) { SysTestRunner runner = SysTestRunner::createTestRunner(classstr(SimpleTests)); ; runner.getResult().addListener(new SysTestListenerPrint()); runner.run(); print runner.getSummary(); pause; }
Actually it does more than that. Let's do a little experiment. Go to Tools > Development Tools > Unit Test > Parameters. Navigate to Listeners tab and select Infolog listener (move it from right to left using the [ Development Tools > Unit Test > Test jobs. Navigate to the last test job (I know there is a bug with sorting of the jobs based on the ID). You should see our SimpleTests in there. Select this record and click on Tests button. A form is displayed with details about all test classes and test methods that were run. Implementing a custom listener


If you need to implement your own listener (logging to a different database, to a file in a certain file format, using a COM or .NET object, etc.) then all you need to do is to implement the SysTestListener interface. The following example demonstrates how to create a “failure” memory listener. The listener will contain only information about failures. To get messages from the memory it will publish getMessages method. public class FailureListener implements SysTestListener { List failures; public void new() { ; failures = new List(Types::String); } public List getMessages() { return failures; } public void addFailure(SysTestListenerData _data) { str message = strfmt('%1: %2', _data.parmTest().getName(), _data.parmMessage()) ; failures.addEnd(message); } public void addInformation(SysTestListenerData _data) { } public void close() { } public void endSuite(SysTestListenerData _data) { } public void endTest(SysTestListenerData _data) { } public void open() { } public void startSuite(SysTestListenerData _data) { } public void startTest(SysTestListenerData _data) { } }
The following sample demonstrates the use of the new listener: static void UsingFailureListener(Args _args) { SysTestSuite suite = new SysTestSuite(classstr(SimpleTests)); SysTestResult result = new SysTestResult(); FailureListener listener = new FailureListener(); ListIterator iterator = null; ; result.addListener(listener); suite.run(result); iterator = new ListIterator(listener.getMessages()); while (iterator.more()) { print iterator.value(); iterator.next(); } print '--------------------------------------------------------------'; print result.getSummary(); pause; }
You can also use any of the available listeners and just extend its behavior. This way you can easily change their formatting for example because most of them have protected write method. You can download these samples: Part05: Execution.xpo
This is all for this post. Next week I'll try to cover code coverage.






==============
Источник: http://blogs.msdn.com/dpokluda/archi...Execution.aspx
 


Ваши права в разделе
Вы не можете создавать новые темы
Вы не можете отвечать в темах
Вы не можете прикреплять вложения
Вы не можете редактировать свои сообщения

BB коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 18:50.
Powered by vBulletin® v3.8.5. Перевод: zCarot
Контактная информация, Реклама.