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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 28.10.2006, 17:43   #1  
Blog bot is offline
Blog bot
Участник
 
25,526 / 847 (80) +++++++
Регистрация: 28.10.2006
Pokluda: SysTest part I.: Assertions and test classes
Источник: http://blogs.msdn.com/dpokluda/archi...ssertions.aspx
==============
In the next series of posts I will demonstrate and explain some of the basic as well as some more advanced features of SysTest.
Test classes

Let's begin with a very simple test. To create a test, derive a class from SysTestCase class. This is all that is needed for SysTest to be able to run tests from this class. This class might have many different methods. How does SysTest know what are the main methods that should be run as unit tests?
SysTest is looking for all the methods with the following signature:
public void test*() All these methods are recognized as unit tests and executed.
Assertions

SysTest offers a wide range of assert methods for you to use in your tests. You can see them all in SysTestAssert class.
Method Meaning assertEquals asserts that the two parameters are equal; when the parameters are classes implementing "equal" method then this method is called to compare them, otherwise they are compared using == operator assertNotEqual oposite to assertEquals assertSame compares the parameters using == operator assertNotSame oposite to assertSame assertRealEquals compares two real values with a provided delta; therefore if you pass number1, number2 and delta, then the assert passes when | number1 - number2 | Development Tools > Unit Test > Show toolbar) then in case of errors/failures, the error messages are displayed in the Infolog. Info messages are ignored in toolbar. If you want to see them you have to either use other test runner (we will cover this topic hopefully sometime later -- if requested) or you write a simple runner yourself. The following job would run our tests:</P> static void RunMySimpleTests(Args _args) { SysTestSuite suite = new SysTestSuite(classstr(MySimpleTests)); SysTestResult result = new SysTestResult(); ; suite.run(result); print result.getSummary(); pause; } There are different listeners (we will cover this in detail sometime later). Toolbar runner is using a modification of SysTestListenerInfolog that displays only error messages. If you want to see all the messages use either SysTestListenerPrint or SysTestListenerInfolog. Or use both. Do you see how flexible this is?
static void RunMySimpleTests(Args _args) { SysTestSuite suite = new SysTestSuite(classstr(MySimpleTests)); SysTestResult result = new SysTestResult(); ; result.addListener(new SysTestListenerPrint()); suite.run(result); print result.getSummary(); pause; } Don't worry for now what all those objects mean, just use this sample as a template for your own jobs. I prefer instead of jobs to add this to the test as main method:
public static void main(Args _params) { SysTestSuite suite = new SysTestSuite(classstr(MySimpleTests)); SysTestResult result = new SysTestResult(); ; result.addListener(new SysTestListenerPrint()); suite.run(result); print result.getSummary(); } Why do I do that? Well because during TestDrivenDevelopment I like to run the tests all the time and there is nothing easier than pressing F5 on my keyboard.
You can download these samples: Part01: Assertions.xpo
That's it for today. In the next post I will try to explain exception handling (expected exceptions) and hopefully much more.


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

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
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

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

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

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