英文:
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的"运行外部工具"按钮创建一个新的外部工具配置,如下所示:
- 在主选项卡上,位置为
C:/Go/bin/go.exe
- 参数为
test
- 工作目录应指向包含要进行测试的包的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:
- on the Main tab the location is
C:/Go/bin/go.exe
- the argument is
test
- the working directory should point to the eclipse workspace folder containing the package that is to be tested (eg
${workspace_loc:/goProject/src/pnp}
, wherepnp
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个内置的构建目标,这些目标是项目构建的方式。
可以在项目资源管理器中查看和配置这些目标:
> 这些模式包括:
> - ./... #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:
> 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.)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论