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

 
 
Опции темы Поиск в этой теме Опции просмотра
Старый 19.11.2007, 03:24   #1  
Blog bot is offline
Blog bot
Участник
 
25,617 / 848 (80) +++++++
Регистрация: 28.10.2006
axaptapedia: Unit Testing
Источник: http://www.axaptapedia.com/Unit_Testing
==============

Summary:
Unit Testing is a common technique in object oriented programming ([[OOP]]). The developer writes test cases for business logic elements. As in object oriented programming the application is built up from classes and objects, unit testing is performed on classes and objects. Test cases can be combined to test suites that cover a certain requirement. The big benefit from unit testing is that it can be automated using unit testing frameworks. Unit testing and testing frameworks are required for a test-driven development approach. Test driven development is common in agile software development like Extreme Programming. Where you first write the the test scenarios that must be accomplished, and afterwards write feature code that passes the test cases.

[[Image:Testdriven.png]]

==Unit Testing in Dynamics AX==
Microsoft ships Dynamics AX 4 with a unit testing framework. The test framework allows developers to write unit tests almost like in JUnit and combine them in test suites. Especially for and ERP environment Microsoft has added multiple transaction isolation levels for the test framework. It is impossible to define transactions around a unit test so that a test run doesn't effect the original data. It is even possible to let the tests run in a new company account. Therefore the original data is never touched by a test case.

===Implementation===
To write a Unit Test first create a new test project. That's a special project type in Dynamics AX 4. In the projects window right click on the "shared" node and select "new" and "test project". The system creates a new test project with a test suite in it. A test suite is a group node for classes. Create a new class that extends the SysTestCase.

/** Test a calculator class */
class TestCalculator extends SysTestCase
{
}

The SysTestCase extends the SysTestAssert class. Thats where all the Assert methods are defined. Create a new test method that checks the basic operations of the Calculator class. A test method must start with the prefix "test". The test class doesn't compile at the moment because the feature code doesn't exist yet.

[[Image:SysTestAssert.png]]


/** Check the basic operations */
public void testOperations()
{
Calculator c = new Calculator(3);
;

this.assertEquals(10,c.add(7)); // 3 + 7 = 10
this.assertEquals(8,c.sub(2)); // 10 - 2 = 8
this.assertEquals(4,c.div(2)); // 8 / 2 = 4
this.assertEquals(12,c.mul(3)); // 4 * 3 = 12
}

Now its time to write feature code. Create a new class Calculator with methods for the basic arithmetic operations and a constructor that accepts a number as initial value.

/** Calculator for basic Integer operations */
class Calculator
{
int value;

void new(int _value = 0)
{
;
value = _value;
}

public int add(int x)
{
;
value = value + x;
return x;
}

public int sub(int x)
{
;
value = value - x;
return x;
}

public int mul(int x)
{
;
value = value * x;
return x;
}

public int div(int x)
{
;
value = value / x;
return x;
}
}

After developing the feature code the test case compiles and can be run the first time. Do this by right click and choose from the context menu "Add In" and "Run Test". Dynamics AX provides you with a lot of information and even code coverage information. The result can be written to the infolog, database or XML file.

[[Image:TestResult.png]]

==Regression Testing==
Regression tests are a common technique in quality assurance on a running project. While optimizing an application it is important to make sure not to destroy already working feature code. This can be done by combining the Version Control System with a test suite. In the settings dialog for the version control system you can append a test project. Modifications can only be checked in if the test project succeeds.

[[Image:Regression.png]]

[[Category:General development]]


Источник: http://www.axaptapedia.com/Unit_Testing
__________________
Расскажите о новых и интересных блогах по Microsoft Dynamics, напишите личное сообщение администратору.
 

Похожие темы
Тема Автор Раздел Ответов Посл. сообщение
Dynamics Mobile: Unit Testing DocumentHandlers With Parameters Blog bot DAX Blogs 0 13.01.2009 14:05
Dynamics Mobile: Unit Testing DocumentHandlers Blog bot DAX Blogs 0 07.01.2009 17:05
mfp: Late night discussions on software development #3: Unit testing Blog bot DAX Blogs 6 17.03.2008 12:01
Dynamics AX: Dynamics AX 4.0 - Unit Testing and Test Projects Blog bot DAX Blogs 0 28.10.2006 16:40

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

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

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