在Eclipse中运行Go测试

huangapple go评论96阅读模式
英文:

Running Go tests in Eclipse

问题

我已经安装了eclipse和goclipse,一切都很好,我可以在IDE中运行控制台应用程序。在IDE中执行单元测试是否也是可能的?

英文:

I have eclipse and goclipse installed, all is well, I can run a console app in the IDE. It is possible to execute the unit tests in the IDE too?

答案1

得分: 5

最新版本的goclipse(0.7.6)提供了使用"testing"包进行测试的方法,假设您已经按照在安装Go时创建的项目结构推荐的方式进行了设置,该结构在C:/Go/doc/code.html中有说明。

使用Eclipse的"运行外部工具"按钮创建一个新的外部工具配置,如下所示:

  1. 在主选项卡上,位置为C:/Go/bin/go.exe
  2. 参数为test
  3. 工作目录应指向包含要进行测试的包的Eclipse工作区文件夹(例如${workspace_loc:/goProject/src/pnp},其中pnp是包的名称,而不是包含测试的go文件的名称)。

现在,您可以按照通常的方式按下运行按钮来运行测试,给配置一个合理的名称,例如:go test pnp。现在,您可以在不同的go文件(或同一个文件)中添加更多的测试,并且所有的测试都将按照预期的方式进行。

英文:

The latest release of goclipse (0.7.6) does provide a means of doing testing using the "testing" package assuming you have followed the project structure recommended in C:/Go/doc/code.html in the installed file structure created when installing Go.

Using the Eclipse "run external tools" button create a new external tool configuration as follows:

  1. on the Main tab the location is C:/Go/bin/go.exe
  2. the argument is test
  3. the working directory should point to the eclipse workspace folder containing the package that is to be tested (eg ${workspace_loc:/goProject/src/pnp}, where pnp is the name of the package NOT the name of the go file that contains the test).

You can now run the test by pressing the Run button in the usual manner, having given the configuration a sensible name eg: go test pnp. You can now add further tests to the package in different go files (or the same one) and all the tests will be carried out in a manner that is expected.

答案2

得分: 3

是的,如果你制作一个makefile来做这个...如果你问的是goclipse是否有像Java的JUnit一样内置的测试工具,答案是否定的。

英文:

Yes it is if you make a makefile to do so... If you are asking if goclipse has a built in testing facility like JUnit for java the answer is no though.

答案3

得分: 3

问题5要求“将'go test'集成到IDE和开发者工作流程中”。

现在该问题已经关闭(2015年8月),使用提交9c3c858(0.11.2之后的下一个版本),具体文档如下:

> 每个Go项目都有3个内置的构建目标,这些目标是项目构建的方式。
可以在项目资源管理器中查看和配置这些目标:

在Eclipse中运行Go测试

> 这些模式包括:

> - ./... #build:默认构建。构建项目中的所有Go包(不包括测试包)。

  • ./... #build-tests:构建项目中的所有Go测试包。
  • ./... #[run-tests]:构建并运行所有Go测试。

> 每个目标可以在Eclipse项目构建时启用或禁用。(尽管同时启用#build-tests#[run-tests]没有太多意义。)

英文:

The issue 5 was asking to "Integrate 'go test' into the IDE and developer workflow."

It now has just been closed (August 2015), with commit 9c3c858 (next release after 0.11.2), with the following documentation:

> Each Go project has 3 built-in Build Targets, which are ways in how the project can be built.
These can be viewed and configured in the Project Explorer:

在Eclipse中运行Go测试

> The modes are:

> - ./... #build: The default build. Builds all Go packages present in the project (excluding test packages).

  • ./... #build-tests: Builds all Go test packages present in the project.
  • ./... #[run-tests]: Builds all and runs Go tests.

> Each target can be enabled or disabled when for Eclipse project builds. (There is not much point to have both #build-tests and #[run-tests] enabled though.)

huangapple
  • 本文由 发表于 2012年1月22日 00:59:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/8954821.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定