Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Use JUnit CN

Revision as of 02:49, 3 October 2006 by Young.yz.gmail.com (Talk | contribs)

本文论述如何在Eclipse 中使用JUnit 进行单元测试。

基本概念

  • TestRunner
  • TestCase
  • TestSuite

使用说明

  • 新建sample 项目,源文件夹为src。
  • 新建并实现Triangle 类,包名为com.ime.sample。
  • 新建源文件夹test。
  • 新建并实现TriangleTest 类,包名为com.ime.sample.test。
  • 使用JUnit 运行TriangleTest。
  • 重构TriangleTest 和Triangle 类。

与Ant 结合生成测试报告

  • 新建并实现build.xml 文件在sample 项目中。
  • 使用Ant 运行build.xml。
  • 在浏览器中查看测试报告。

使用测试框架进行插件的测试

  • 下载Automated Testing for Custom Plugins 包,并解压缩到自定义的目录下(如:G:\Custom-plugin-testing)。
  • 将解包的Eclipse SDK3.1.1 和Eclispe Test Framework3.1.1 解压缩到/eclipse-utp/ 目录下。
  • 将做成的Test plugin 和Tested plugin 及依赖放到/eclipse-custom/目录下。
  • 修改/label.properties 适配Build 信息。
  • 修改/tests.xml、/tests.properties 添加自定义插件的测试任务。
  • 双击/runt-cmd.bat,在命令行窗口中键入runtests [参数]运行测试。
  • 查看在/generate/results 目录下生成的测试报告。

Back to the top