Automated Testing for Custom Plugins
使用插件测试框架测试用户开发的插件说明:
  • 目录结构 /eclipse-custom/ 存放Test plugin 和Tested plugin 的文件夹。 /eclipse-utp/ Eclipse SDK,Test Framework 及其他依赖项。 /generate/ 运行时生成的内容。 /readme.html 自定义插件的自动测试框架简介。 /run-cmd.bat 启动dos 命令行窗口。 /runtests.bat Windows 命令行测试命令。 /label.properties Build 的属性文件。 /tests.properties 测试插件的属性文件。 /tests.xml 测试的Ant 配置。 /junit.xml 测试报告格式。 /generate/results/ 自定义插件的测试报告,包括html 和xml 两种格式。 /generate/test-eclipse/ 自定义插件的Test 运行环境。 /generate/workspace-utp/ Eclispe Ant 的运行工作区间。
  • 使用方法 1、将解包的Eclipse SDK3.1.1 和Eclispe Test Framework3.1.1 解压缩到/eclipse-utp/ 目录下。 2、将做成的Test plugin 和Tested plugin 及依赖放到/eclipse-custom/目录下。 3、修改/label.properties 适配Build 信息。 4、修改/tests.xml、/tests.properties 添加自定义插件的测试任务。 5、双击/runt-cmd.bat,在命令行窗口中键入runtests [参数]运行测试。
  • 如何开发Test plugin 1、新建一个空[插件项目],添加[被测试插件]和[JUnit 插件]等依赖项。 a、如果被测插件没有Exported 它的所有包,将其全部Exported。 b、如果测试用到jmock interface, 给Test plugin 添加[com.jmock.support]依赖项,再将jmock jar 包添加到Java Build Path。 c、如果测试用到jmock class, 除进行b、操作外还要将jmock-cglib jar 包添加到Java Build Path, 并且给[被测试插件]添加[com.jmock.support]依赖项。 2、设计并完成Test suite 和Test case。 a、在开发、Debug、修改Bug 之前要先写测试用例。 b、区分UI 测试与Core 测试,UI 部分可以只测试业务方法的逻辑是否正确。 c、提供一个测试环境助手TestContextHelper 类。 d、[正常/边界/异常]等情况均要测试。 e、测试类与被测试类放在同一包下,以便测试受保护方法。 f、关注重点功能、重点类、重点方法,不要让测试代码的复杂度超过被测试代码的复杂度。 g、测试固定动作而不是具体实现。 h、在单元测试中捕获代码注释。 i、避免在单元测试中使用特定于域的对象。 h、测试内容:返回值[get()]、副作用[init()]、操作结果[save()]、操作过程[finish()]。 最好将该逻辑应用到基础结构中。一个优秀的测试程序应当满足以下条件: 初始化设置。 //Setup 定义期待值。 //Expected 运行测试单元。 //Exectue 获取实际值。 //Actual 断言是否匹配。 //Assert 一套适当的单元测试具有以下功能: 从程序员角度看问题 说明可能的最实用设计 提供类文档的最佳格式 确定一个类何时完成 增强开发人员对代码的信心 作为快速重构的基础 一套适当的功能测试具有以下功能: 从用户角度看问题 以有效方式捕获用户需求 增强小组(用户和开发人员)在系统满足用户需求方面的信心 在编写单元测试时,我根据以下原则来确定当前编写的单元测试实际上是否是功能测试: 如果单元测试跨越类边界,则它就可能是功能测试。 如果单元测试变得很复杂,则它可能是功能测试。 如果单元测试很脆弱(虽然它是一个有效测试,但它必须不断改变以处理不同的用户组合), 则它可能是功能测试。 如果编写单元测试比编写其所测试的代码更难,则它可能是功能测试。 3、新建test.xml 文件,指定测试任务Test suite,放在测试插件的根目录下。 Sample: 在插件的/test.xml 中指定测试任务 <target name="suite"> <property name="test-plugins" value="${eclipse-home}/workspace-test" /> <delete dir="${test-plugins}" quiet="true" /> <ant target="ui-test" antfile="${library-file}" dir="${eclipse-home}"> <property name="data-dir" value="${test-plugins}" /> <property name="plugin-name" value="${plugin-name}" /> <property name="classname" value="com.sampletool.tests.AllSampleToolTests" /> </ant> </target>
  • 如何修改/tests.xml、/tests.properties、/label.properties Sample: 在/tests.xml 中添加新任务 <target name="ejbtool" description="Runs the com.sampletool.tests_1.0.0 test.xml"> <antcall target="runtests"> <param name="testPlugin" value="${com.sampletool.tests}" /> <param name="report" value="com.sampletool.tests" /> </antcall> </target> Sample: 在/tests.properties 中添加新任务对应的属性 com.sampletool.tests=com.sampletool.tests_1.0.0 com.sampletool.tests_1.0.0.has.performance.target=true Sample: 修改label.properties 中的相应属性值 builddate=September 29, 2005 buildtype=M buildId=M20050929-0840 timestamp=200509290840 buildLabel=M20050929-0840
  • 命令runtests 的参数说明 runtests [-os <operating system>] [-ws <windowing system>] [-arch <architecture>] [-noclean] [<testTarget>] [-properties <path>] [-vm <path to java executable>] Sample: runtests -noclean ejbtool [回车]
    Parameter Description
    -os <operating system> The OS the tests are being run on. One of: aix, hpux, linux, qnx, solaris, win32. Default win32
    -ws <windowing system> The windowing system the tests are being run on. One of: motif, gtk, photon, win32. Default win32
    -arch <architecture> The architecture the tests are being run on. One of: ppc, PA_RISC, x86, sparc. Default x86
    -noclean Run tests without installing a clean Eclipse between test targets. Default is to install a clean Eclipse between test targets.
    <testTarget> The ant task.
    -properties Used to reference a properties file containing additional Ant properties used in running tests.Can be used to pass additional vm arguments to the Java virtual machine running the tests by adding the entry "extraVMargs=<the args to pass to the vm>" to the specified properties file.
    -vm The full path to the java executable with which to run the tests. Use this to specify a specific virtual machine with which to run the tests. For example, "-vm c:\jdk142\jre\bin\java". Default set to "java" (i.e. java executable on system path).
  • Created by yangyz@IME 2006-4-25.