XAF 帮助文档翻译 EasyTest Basics(基础)

EasyTest Basics(基础)

eXpressApp Framework > Concepts > Functional Testing > EasyTest 基础

The eXpressApp Framework includes its own functional testing engine - EasyTest. All you need to know to use it is a set of commands allowed by test scripts. Using a custom script language has strong advantages - you write tests in terms of XAF. As a result, your tests will work for both Windows Forms and ASP.NET Web applications. This topic describes the basics of using EasyTest, and the components it comprises. For step-by-step instructions on how to test your XAF applications, refer to the How to: Test an XAF Application topic.
XAF
包括它自己的功能测试引擎-EasyTest.所有你需要知道用它,它是一套允许通过测试脚本执行的命令。用自定义脚本语言有很强的优势-你写测试在开发XAF中。因此,你为Windows Forms ASP.NET Web applications测试。本主题描述EasyTest基础,这个构件包括一步一步介绍如何测试你的XAF应用程序,请参考如何测试一个XAF应用程序。

EasyTest Components

When you create a new XAF solution, the FunctionalTests folder is added to the module project:
当你创建一个新的XAF项目时,FunctionalTests文件夹被添加到模块工程:

By default, this folder contains the EasyTest configuration file and the Sample.ets sample test script file. You can use the sample test script to quickly get a general idea of the script syntax. EasyTest requires that the Config.xml configuration file is present in the folder containing a test script, to be able to perform the test script. This file serves as a central storage for the configuration information required by the test scripts. The configuration file created by default contains application definitions for the solution's application project. You can create test scripts in any folder. However, since the FunctionalTests folder contains the automatically generated configuration file, it is recommended that you store test scripts here. To learn more about the configuration file, refer to the EasyTest Configuration topic.
默认情况下,这个文件夹包括EasyTest configuration fileSample.ets例子测试脚本文件。你能用例子测试脚本快速了解脚本的常用语法。EasyTest需要Config.xml配置文件,存在FunctionalTests文件夹中,能执行这个测试脚本。这个文件存储所有测试脚本的配置信息。这个文件夹默认自动创建在模块工程。你可以在任何文件夹创建测试脚本。然而,由于FunctionalTests文件夹包含自动生成的配置文件,建议你在这里存储测试脚本。了解更多关于配置文件信息,请参考EasyTest配置主题。

New solutions are created with a separate EasyTest connection string defined in the application projects' configuration files. This connection string is named EasyTestConnectionString. So, while testing, the applications will use the database specified by this connection string.
建立新项目用一个独立EasyTest连接字符串定义在应用程序工程配置文件中。这个连接字符串的命名为EasyTestConnectionString.因此,在测试时,应用程序将通过连接字符串用这个数据库。

Create Test Scripts (建立测试脚本)

Test scripts can be created in two ways:
两种方法能创建测试脚本:

  • Manually (手动建立)

Right-click the FunctionalTests folder and select Add New Item. In the Add New Item dialog, select Text File, enter a name and change the file extension to ETS. After that, you can enter the required script via the Visual Studio text editor. Refer to the EasyTest Script Reference topic, for a list of available script commands.
右键单击FunctionalTests文件夹,选择添加新项。在添加新项对话框中,选择Text File,输入名称,更改扩展名为ETS.然后,在Visual Studio的文本编辑器中输入需要的脚本。请参考EasyTest Script Reference主题,给出可用的脚本命令。

  • Use the EasyTest script recorder(EasyTest脚本记录器)

EasyTest is shipped with the script recorder which can record the actions you perform on a UI, and save them to an EasyTest script file. To learn how to use the script recorder, refer to the Script Recorder Module topic.
EasyTest
附带脚本记录器,能记录在用户界面上操作的动作,然后保存到一个EasyTest脚本文件。要了解如何用脚本记录器,请参考脚本记录器模块主题。

To see test script examples, refer to the XCRM demo installed with XAF. This demo application contains about two dozen sample test scripts you can use, to learn EasyTest. The XCRM demo is located in the C:\Users\Public\Documents\DevExpress 2010.2 Demos\eXpressApp Framework\XCRM folder, by default.
要看测试脚本例子,请参考XCRM实例同XAF一起安装。这个实例应用程序包含大约2打测试脚本例子可用。默认,XCRM实例在本地文件夹C:\Users\Public\Documents\DevExpress 2010.2 Demos\eXpressApp Framework\XCRM

Run Tests (执行测试)

EasyTest has its testing functionality integrated into Visual Studio. So, you can test your applications from Visual Studio while developing them. EasyTest supplies a set of actions for a context menu available when editing ETS script files in the Visual Studio text editor, and in the Solution Explorer when clicking over an ETS file:
EasyTest
测试功能集成在Visual Studio中。因此,当开发XAF应用程序时,可用用Visual Studio测试应用程序。当在Visual Studio中编辑ETS测试脚本时,EasyTest提供了一组可用的动作菜单,在项目浏览器中,当在一个ETS文件上单击右键: 

The context menu contains the following actions:
这个上下文菜单包含项目动作:

Action(动作)

Description(描述)

Run(执行)

Performs a whole test.(执行一整个测试)

Run Next Stop(下个执行)

Performs a test script on a by-command basis. To perform the whole test, this action must be performed as many times as there are test commands in the test file.
通过基础命令执行一个测试脚本。要执行整个测试,这个动作必须被执行多次测试命令在一个测试文件中。

Run to Cursor(执行到光标处)

Active only in the Visual Studio text editor when editing an ETS file. Performs the test up to the cursor's position, after which test execution is paused.
仅在Visual Studio中,当编辑一个ETS文件时。执行测试到光标的位置,之后测试暂停。

Stop Running(停止执行)

Stops the test being run.(停止正在执行的测试)

All these commands are also available on the EasyTest toolbar, which is disabled by default:
所有命令也在EasyTest工具栏上可用,默认情况下禁用:

Note(备注)

Administrative privileges may be required to run Easy Test Scripts. So, if a script fails to run, try to start Visual Studio as an administrator.
运行EasyTest脚本需要管理员权限,因此,如果脚本运行失败,请用管理员权限启动Visual Studio.

You can run multiple tests in a batch. To do this, select the required test script files in the Solution Explorer before using the context menu's Run action. You can also invoke the context menu for the module project or the FunctionalTests folder. In this instance, if you use the Run action, all the existing scripts will be executed. When using the Run Next Step action to perform several tests, the selected tests are put into a queue, and performed as if they represented a single test. So, if you have reached the last command in test one and use the Run Next Step action, the first command from test two will be executed
在一个批处理中你可用执行多个测试。要做到这一点,用上下文菜单的执行动作之前,选择需要执行的测试脚本文件在项目浏览器中。你也可为模块工程或FunctionalTests文件夹调用上下文菜单。在这种情况下,如果你用执行动作,所有存在的脚本将被执行。当用Run Next Step动作执行几个测试,选择的测试放入一个队列,并表示,如果他们表现为一个单一的测试。因此,如果你执行到一个测试的最后命令,用Run Next Step 动作,从第一个命令开始从第二个测试执行。

When performing multiple tests, if a certain test command cannot be executed, the current script file execution is interrupted. The error and the corresponding script row number are written to the Output Window. Then, the next script file is executed. The Output Window contains a simple log describing the process and the result of the test:
当执行多个测试时,如果某个测试命令不能执行,当前执行脚本被中断。错误和相应的脚本行号写到Output Window. 接着,需要脚本文件执行。Output Window 包含一个例子日志,描述测试过程:

When a test fails, in addition to the error message, a screenshot is taken capturing the state of the application's UI at the time of failure. Currently, the screenshot is represented by a JPEG file for Windows Forms applications and an HTML page for ASP.NET Web applications. You can open the screenshot by double clicking its name in the Visual Studio Output window, if an association exists between the screenshot file's extension (JPEG or HTML) and a corresponding editor. To learn how to set up associations, refer to the How to: Change or Add a Default Editor MSDN article.
当一个测试失败,除了错误信息,还有一个应用程序失败时的截图。当前,这个截图是一个JPEG文件在Windows Forms应用程序中,在ASP.NET Web应用程序中是一个HTML页面。你可以在Visual StudioOutput Window中双击他的名称打开截屏,如果关联存在的截屏文件的扩张和相应的编辑器。要了解如何设置关联,请参考如何:更改或添加默认编辑器MSDN文章。

You can also set up a breakpoint, as in a regular Visual Studio solution:
你也可以设置一个断点,想在常规Visual Studio项目中:

When a test execution is paused at a breakpoint, you can resume execution of the test up to the last command or step-by-step, using the appropriate context menu actions.
当一个执行的测试在断点出暂停,你可以进行执行到最后命令或一步一步测试,使用相应的上下文菜单动作。

EasyTest script files can also be performed by a stand-alone test executor tool. To learn more about it, refer to the TestExecutor Utility topic.
EasyTest
脚本文件能被一个独立的测试工具执行。要了解更多关于这方面的知识,请参考TestExecutor Utility主题。

Remove EasyTest Components from an XAF Application
移除EasyTest组件从XAF应用程序

You can remove all EasyTest components from your application, if necessary. In this case, delete the following:
如果需要,你可以从你的应用程序中移除所有EasyTest组件。在这中情况下,删除下面这些:

Add EasyTest Components to an Existing XAF Application
為已存在的XAF應用程序添加EasyTest組件。

To be able to test an existing application created with DXperience versions prior to v2009 vol2, you will need to update its solution first.
要讓已經存在的應用程序用DXperience v2009 vol2之前的版本能測試,需要首先更新他的項目。

In a Windows Forms application project, the following methods must be updated:
在一個WindowsForms應用程序工程,必須按照以下方法更新:

  1. The DatabaseVersionMismatch method in the WinApplication.cs (WinApplication.vb) file: port specified in the EasyTest Config.xml configuration file.
    Windows Forms 應用程序更新添加DevExpress.ExpressApp.EasyTest.WinAdapter引用。注意用端口4100作為參數,必須跟EasyTest Config.xml 配置文件中的設置一致。.

In an ASP.NET Web application project, the following methods must be updated:
在一個ASP.NET Web應用程序工程,必須按照以下方法更新:

  1. The DatabaseVersionMismatch method in the WebApplication.cs (WebApplication.vb) file:
    private void MySolutionWindowsFormsApplication_DatabaseVersionMismatch(
        
    object sender, DevExpress.ExpressApp.DatabaseVersionMismatchEventArgs e) {
    #if DEBUG
        e.Updater.Update();
        e.Handled 
    = true;
    #else 
        
    if (System.Diagnostics.Debugger.IsAttached) {
        }
        
    else {    }
    #endif 
    }
    The Main method in the Program.cs (Program.vb) file:
    static void Main() {
    #if DEBUG
        DevExpress.ExpressApp.EasyTest.WinAdapter.RemotingRegistration.Register(
    4100);
    #endif 
    //.... 
    }

    Add a reference to the DevExpress.ExpressApp.EasyTest.WinAdapter assembly to the Windows Forms application project. Note that the port passed as the parameter (4100 in this sample) must match the port specified in the EasyTest Config.xml configuration file.
    Windows Forms 應用程序更新添加DevExpress.ExpressApp.EasyTest.WinAdapter引用。注意用端口4100作為參數,必須跟EasyTest Config.xml 配置文件中的設置一致。.

    In an ASP.NET Web application project, the following methods must be updated:
    在一個ASP.NET Web應用程序工程,必須按照以下方法更新:

    1. The DatabaseVersionMismatch method in the WebApplication.cs (WebApplication.vb) file:
      private void MySolutionAspNetApplication_DatabaseVersionMismatch(
          
      object sender, DevExpress.ExpressApp.DatabaseVersionMismatchEventArgs e) {
      #if DEBUG
          e.Updater.Update();
          e.Handled 
      = true;
      #else 
          
      if (System.Diagnostics.Debugger.IsAttached) {
              
      //... 
          }
          
      else {
              
      //... 
          }
      #endif }

      The Application_Start method in the Global.asax.cs (Global.asax.vb) file:

      protected void Application_Start(Object sender, EventArgs e) {
          WebApplication.OldStyleLayout 
      = false;

      #if DEBUG
          DevExpress.ExpressApp.Web.TestScripts.TestScriptsManager.EasyTestEnabled 
      = true;
          ConfirmationsHelper.IsConfirmationsEnabled 
      = false;
      #endif 
      }

    The ASP.NET Web application project's Web.config file needs to be updated as well. Add the following line:

    <add verb="*" path="TestControls.axd"

        type="DevExpress.ExpressApp.Web.TestScripts.TestScriptsManager"/>

  2.  

    This line should be added to the system.web \ httpHandlers element, so that it looks like this:

     

    <system.web>
        
    <!-- ... -->
        
    <httpHandlers>
            
    <add verb="*" path="TestControls.axd"
                type
    ="DevExpress.ExpressApp.Web.TestScripts.TestScriptsManager"/>
        
    <!-- ... -->
        
    </httpHandlers>
        
    <!-- ... -->
    </system.web>

     

  3. the application projects' configuration files. So, you may want to backup the databases used by the applications before running any actual tests.
    注意:這種方法更新項目之後,EasyTest將用應用程序項目的配置文件中的指定數據庫鏈接字符串。因此,使用應用程序運行任何實際測試前,你可能要部份數據庫

See Also

EasyTest Troubleshooting Guide

 

欢迎转载,转载请注明出处:http://www.cnblogs.com/Tonyyang/

 

 

原文地址:https://www.cnblogs.com/Tonyyang/p/2029259.html