How to: Test an XAF Application |
|
eXpressApp Framework > Task-Based Help > How to: Test an XAF Application
The eXpressApp Framework is shipped with EasyTest - a test framework designed to perform functional testing of XAF applications. This topic demonstrates how to test an XAF application. A custom Controller will be implemented. Then, its functionality will be tested via EasyTest. To learn more about EasyTest, refer to the EasyTest Basics topic.
XAF附带一个测试框架设计执行XAF应用程序功能测试-EasyTest。本篇演示如何测试XAF应用程序。实现一个自定义控件。然后,用EaseyTest进行他的功能测试。了解更多关于EasyTest,请参考EasyTest基础主题。
|
The complete sample project is available in the DevExpress Code Central database at http://www.devexpress.com/example=E1619. Depending on the target platform type (ASP.NET, WinForms, etc), you can either run this example online or download an auto-executable sample. |
This topic is comprised of two parts.(这个主题包含两个部分)
- A custom Controller implementation. This Controller will contain a custom Action.
一个自定义控件实现。这个控件包括一个自定义按钮。 - Step-by-step instructions on how to test an implemented Controller.
一步一步介绍如何测试一个实现的控件。
Implement a Custom Controller(实现一个自定义控件)
Create a new XAF application solution named PostponeControllerTest. The custom Controller will perform an Action over Task business objects. The sample Task business class exposes two properties - Description and DueDate.
创建一个新的XAF应用程序项目,命名为PostponeControllerTest.这个相当于控件将执行一个动作在Task业务逻辑对象。这个例子Task业务类公开了两个属性-Description和DueDate.
| ||||||
[DefaultClassOptions] public class Task : BaseObject { public Task(Session session) : base(session) { } public string Description { get { return GetPropertyValue<string>("Description"); } set { SetPropertyValue<string>("Description", value); } } public DateTime DueDate { get { return GetPropertyValue<DateTime>("DueDate"); } set { SetPropertyValue<DateTime>("DueDate", value); } } }
|
The custom Controller is targeted for List Views and contains the Postpone Action. This Action processes the selected objects in a Task List View. The Action adds one day to the objects' DueDate property values.
这个自定义控件是面向列表视图和包括Postpone动作。这动作处理选择对象在Task列表视图中。这个动作添加一天给这个对象的DueDate属性值。
| ||||||
using System.Collections; //... public partial class PostponeController : ViewController { public PostponeController() { InitializeComponent(); RegisterActions(components); this.TargetViewType = ViewType.ListView; this.TargetObjectType = typeof(Task); this.Postpone.Execute += new SimpleActionExecuteEventHandler(Postpone_Execute); } void Postpone_Execute(object sender, SimpleActionExecuteEventArgs e) { IList selectedObjects = ((ListView)View).SelectedObjects; foreach (object selectedObject in selectedObjects) { Task selectedTask = (Task)selectedObject; if (selectedTask.DueDate == DateTime.MinValue) { selectedTask.DueDate = DateTime.Now; } selectedTask.DueDate = selectedTask.DueDate.AddDays(1); } } }
|
Test the Custom Action (测试自定义动作)
This section describes a way of creating an EasyTest script that ensures that the implemented Postpone Action works as expected. The test will work for both Windows Forms and ASP.NET Web applications.
这个片段描述一个创建一个EasyTest脚本的方法,确保实现Postpone动作预期执行。这个测试可以在两种平台上工作(WinForms and ASP.NET Web applications)
- In Solution Explorer, navigate to the module project:
在项目浏览器,导向模块工程
Right-click the FunctionalTests folder and select Add New Item. In the Add New Item dialog, select Text File and enter the "PostponeControllerTest.ets" as the new file's name. When the Visual Studio text editor is invoked, enter the following code.
右击FunctionalTests文件夹,选择添加新项目,在项目对话框选择TextFile,输入“PostponeCOntrollerTest.ets”作为新文件的名称。用Visual Studio文本编辑器编辑,输入以下代码
#DropDB PostponeControllerTestEasyTest
#Application PostponeControllerTestWin
#Application PostponeControllerTestWeb
*Action Navigation(Task)
*Action New
*FillForm
Description = Test Task
Due Date =
*Action Save and Close
*Action New
*FillForm
Description = Test Task Two
Due Date =
*Action Save and Close
#IfDef PostponeControllerTestWeb
*Action Navigation(Task)
#EndIf
*SelectRecords
Columns = Description
Row = Test Task
Row = Test Task Two
*Action Postpone
*CheckTable
Columns = 'Due Date'
Row =
Row =
This script creates two Task objects, selects them in the List View and executes the Postpone Action. After that, the script ensures that the test objects' DueDate properties' values change as expected. For detailed information on the EasyTest command syntax, refer to the EasyTest Script Reference topic.
这个脚本创建两个任务对象,选择他们在列表视图中,执行Postpone动作。之后,这个脚本确保测试对象的DueDate属性的值预期改变。更详细信息关于EasyTest命令语法,请参考EaseyTestScript主题
- Save the test script. Right-click this file in Solution Explorer and select Run:
保存测试脚本。在项目浏览器中右击这个文件,选择Run:
The test will first be executed in the Windows Forms application, and then in the ASP.NET Web Site (This is specified by the second and third commands of the test script). You will then see the following output, indicating that all tests passed successfully.
首先在WindowsForms应用程序上执行,然后在ASP.NET Web Site执行。你将看到下面输出,显示所有的测试通过成功。
See Also(也可)
欢迎转载,转载请注明出处:http://www.cnblogs.com/Tonyyang/
欢迎转载,转载请注明出处:http://www.cnblogs.com/Tonyyang/