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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 28.10.2006, 17:43   #1  
Blog bot is offline
Blog bot
Участник
 
25,643 / 848 (80) +++++++
Регистрация: 28.10.2006
Pokluda: SysTest part II.: Exceptions
Источник: http://blogs.msdn.com/dpokluda/archi...xceptions.aspx
==============
In this post I will try to describe exceptions handling using SysTest.
Very often applications throw exceptions and we have to be able to handle these situations correctly in our UnitTests. Let's say we have the following application class:
public class ThrowingApp { public static ThrowingApp construct() { ; return new ThrowingApp(); } public void throwingErrorException() { ; throw Exception::Error; } } To write a test for this method verifying that it really throws the exception we can write the following UnitTest:
void testThrowErrorException() { ThrowingApp theApp = ThrowingApp::construct(); ; try { theApp.throwingErrorException(); this.fail('Method throwErrorException didn\'t throw an exception.'); } catch(Exception::Error) { this.info('An expected exception has been caught.'); } } This works but SysTest offers another way of handling exceptions. SysTestCase provides parmExceptionExpected property to specify that the test expects the calling code to throw an exception. To do so set parmExceptionExpected property to true.
void testThrowErrorException2() { ThrowingApp theApp = ThrowingApp::construct(); ; this.parmExceptionExpected(true); theApp.throwingErrorException(); } This test is doing the same thing as the previous one. The property can actually do even more. Let's add the following two methods to our ThrowingApp class.
public void throwingErrorMessage() { ; throw error('Error message threw'); } public void postingErrorMessage() { ; error('Error message posted'); } The paramater parmExceptionExpected has an additional optional parameter named _exceptionMessage where you can specify a message that is expected to be thrown:
void testThrowErrorMessage() { ThrowingApp theApp = ThrowingApp::construct(); ; this.parmExceptionExpected(true, 'Error message threw'); theApp.throwingErrorMessage(); }
The same is valid also for error messages that are just added to the Infolog (they don't have to be thrown).
void testPostErrorMessage() { ThrowingApp theApp = ThrowingApp::construct(); ; this.parmExceptionExpected(true, 'Error message posted'); theApp.postingErrorMessage(); } If the class throws an exception but the exception/error message is different than expected then SysTest will fail the test and correctly report expected exception/error message:
void testPostErrorMessage2() { ThrowingApp theApp = ThrowingApp::construct(); ; this.parmExceptionExpected(true, 'Different error message'); theApp.postingErrorMessage(); } When you execute this test (using SysTest toolbar for example: Tools > Development Tools > Unit Test > Show toolbar) you see the following error message:
Error: [myExceptionTest.testPostErrorMessage] Failure: An exception was expected to be thrown! (Expected: Different error message) You can download these samples: Part02: Exceptions.xpo
In the next post I will try to describe test suites and their different "flavors".


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

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
Pokluda: SysTest part VI.: Code coverage Blog bot DAX Blogs 0 08.03.2007 00:44
Pokluda: SysTest part V.: Test execution (results, runners and listeners) Blog bot DAX Blogs 0 28.10.2006 17:43
Pokluda: SysTest part IV.: Test/Suite initialization and cleaning; Execution isolation Blog bot DAX Blogs 0 28.10.2006 17:43
Pokluda: SysTest part III.: Introduction to test suites Blog bot DAX Blogs 0 28.10.2006 17:43
Pokluda: SysTest part I.: Assertions and test classes Blog bot DAX Blogs 0 28.10.2006 17:43

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

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

Рейтинг@Mail.ru
Часовой пояс GMT +3, время: 02:08.